sensors.html 11.4 KB
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>hueplusplus: Sensors</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">hueplusplus
   &#160;<span id="projectnumber">1.0.0</span>
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">Sensors </div>  </div>
</div><!--header-->
<div class="contents">
<div class="toc"><h3>Table of Contents</h3>
<ul><ul><li class="level2"><a href="#autotoc_md17">Sensor support</a><ul><li class="level3"><a href="#autotoc_md18">Working with a known sensor</a></li>
<li class="level3"><a href="#autotoc_md19">Working with an unknown sensor</a></li>
</ul>
</li>
<li class="level2"><a href="#autotoc_md20">ZLL sensors vs. CLIP sensors</a></li>
<li class="level2"><a href="#autotoc_md21">Creating conditions</a></li>
</ul>
</ul>
</div>
<div class="textblock"><p>The library supports the sensor types listed on the Hue developer documentation. Include <code><a class="el" href="_z_l_l_sensors_8h.html">hueplusplus/ZLLSensors.h</a></code> for ZigBee sensors and <code><a class="el" href="_c_l_i_p_sensors_8h.html">hueplusplus/CLIPSensors.h</a></code> for CLIP sensors. Other sensors can be used with the generic <a class="el" href="classhueplusplus_1_1_sensor.html">Sensor</a> class.</p>
<p>In most cases, the type of the sensors is known in advance, such as a switch. The classes in the <a class="el" href="namespacehueplusplus_1_1sensors.html">sensors</a> namespace provide the documented functionality. The type can be specified when accessing the sensor. When it does not match, an exception is thrown. </p><div class="fragment"><div class="line">    <a class="code" href="classhueplusplus_1_1sensors_1_1_z_l_l_switch.html">hueplusplus::sensors::ZLLSwitch</a> switchSensor = bridge.<a class="code" href="classhueplusplus_1_1_bridge.html#acd15a988fecd561103a06e5a4ec8780b">sensors</a>().<a class="code" href="classhueplusplus_1_1_sensor_list.html#a3dcafc979eaa60e7b725ae50488be6df">getAsType</a>&lt;<a class="code" href="classhueplusplus_1_1sensors_1_1_z_l_l_switch.html">hueplusplus::sensors::ZLLSwitch</a>&gt;(2);</div></div><!-- fragment --><p> You can also get all sensors of a specified type by using <a class="el" href="classhueplusplus_1_1_sensor_list.html#a5f6cd913954558252ef97ead28890ec3">getAllByType&lt;T&gt;()</a>. </p><div class="fragment"><div class="line">    std::vector&lt;hueplusplus::sensors::ZLLSwitch&gt; allSwitches</div><div class="line">        = bridge.<a class="code" href="classhueplusplus_1_1_bridge.html#acd15a988fecd561103a06e5a4ec8780b">sensors</a>().<a class="code" href="classhueplusplus_1_1_sensor_list.html#a5f6cd913954558252ef97ead28890ec3">getAllByType</a>&lt;<a class="code" href="classhueplusplus_1_1sensors_1_1_z_l_l_switch.html">hueplusplus::sensors::ZLLSwitch</a>&gt;();</div></div><!-- fragment --> <p>When the sensor type is not known, use the generic sensor class. In this case, some attributes might not exist, so they have to be checked first. This applies to all attributes that have a <code>hasXXX</code> method. </p><div class="fragment"><div class="line">    <a class="code" href="classhueplusplus_1_1_sensor.html">hueplusplus::Sensor</a> genericSensor = bridge.<a class="code" href="classhueplusplus_1_1_bridge.html#acd15a988fecd561103a06e5a4ec8780b">sensors</a>().<a class="code" href="classhueplusplus_1_1_resource_list.html#a7bcf2ed48e70e9f11a4b6bdc24e0e611">get</a>(1);</div><div class="line">    <span class="keywordflow">if</span> (genericSensor.<a class="code" href="classhueplusplus_1_1_sensor.html#a5853efc3712fe6c9e398c5a5b77c4f25">hasOn</a>())</div><div class="line">    {</div><div class="line">        <span class="comment">// Now can check whether it is on</span></div><div class="line">        <span class="keywordflow">if</span> (genericSensor.<a class="code" href="classhueplusplus_1_1_sensor.html#a4b29e3f514c6af3c219f399c3dac1d42">isOn</a>())</div><div class="line">        {</div><div class="line">            <span class="comment">// ...</span></div><div class="line">        }</div><div class="line">    }</div></div><!-- fragment --><p> It is easiest to compare the sensor type to the existing ones (<code>typeStr</code> on the specific sensor classes) and then convert the sensor to that type. </p><div class="fragment"><div class="line">    <a class="code" href="classhueplusplus_1_1_sensor.html">hueplusplus::Sensor</a> genericSensor = bridge.<a class="code" href="classhueplusplus_1_1_bridge.html#acd15a988fecd561103a06e5a4ec8780b">sensors</a>().<a class="code" href="classhueplusplus_1_1_resource_list.html#a7bcf2ed48e70e9f11a4b6bdc24e0e611">get</a>(1);</div><div class="line">    <span class="keywordflow">if</span> (genericSensor.<a class="code" href="classhueplusplus_1_1_base_device.html#a6741ba9ec72108ca0101d41c0b02c568">getType</a>() == <a class="code" href="classhueplusplus_1_1sensors_1_1_z_l_l_switch.html#ab3bdfb9b3704d3102638af059e560455">hueplusplus::sensors::ZLLSwitch::typeStr</a>)</div><div class="line">    {</div><div class="line">        <a class="code" href="classhueplusplus_1_1sensors_1_1_z_l_l_switch.html">hueplusplus::sensors::ZLLSwitch</a> switchSensor = genericSensor.<a class="code" href="classhueplusplus_1_1_sensor.html#a3dd55641f02c9a59f69dd37b87f9d621">asSensorType</a>&lt;<a class="code" href="classhueplusplus_1_1sensors_1_1_z_l_l_switch.html">hueplusplus::sensors::ZLLSwitch</a>&gt;();</div><div class="line">        <span class="comment">// ...</span></div><div class="line">    }</div></div><!-- fragment --> <p>ZLL sensors (defined in <code><a class="el" href="_z_l_l_sensors_8h.html">ZLLSensors.h</a></code>) are physical device sensors which send their data to the bridge using ZigBee. They are added in the same way as lights are, using <a class="el" href="classhueplusplus_1_1_searchable_resource_list.html#aa67cf6cc3bde30b1c8a79d98d270ae32">search()</a>.</p>
<p>CLIP sensors (in <code><a class="el" href="_c_l_i_p_sensors_8h.html">CLIPSensors.h</a></code>) are added using <a class="el" href="classhueplusplus_1_1_createable_resource_list.html#abf886bbd80f86e00a66c7ad61bd773c9">create()</a> with <a class="el" href="classhueplusplus_1_1_create_sensor.html">CreateSensor</a> for parameters. In general, which config and state attributes exist is specified when the sensor is created. The values of CLIP sensors can be changed using requests, unlike ZLL sensors. They can also have a URL to query from.</p>
<p>The most important use for sensors is in <a class="el" href="classhueplusplus_1_1_rule.html">Rules</a>, to trigger changes. Conditions can be created from the specific sensor types using <code><a class="el" href="namespacehueplusplus_1_1sensors.html#a06dd5755779d2fc8df7108940319f7df">makeCondition()</a></code>.</p>
<p>These functions return a helper class with methods for the <a class="el" href="classhueplusplus_1_1_condition.html#a8a66cda007f5cf01934f71c02c03cf35">possible operators</a> valid for the state.</p>
<p>For some sensors, which have multiple possible states, there exist multiple variations of makeCondition. </p><div class="fragment"><div class="line">    <a class="code" href="classhueplusplus_1_1sensors_1_1_z_l_l_switch.html">hueplusplus::sensors::ZLLSwitch</a> switchSensor = bridge.<a class="code" href="classhueplusplus_1_1_bridge.html#acd15a988fecd561103a06e5a4ec8780b">sensors</a>().<a class="code" href="classhueplusplus_1_1_sensor_list.html#a3dcafc979eaa60e7b725ae50488be6df">getAsType</a>&lt;<a class="code" href="classhueplusplus_1_1sensors_1_1_z_l_l_switch.html">hueplusplus::sensors::ZLLSwitch</a>&gt;(2);</div><div class="line">    <span class="comment">// ZLLSwitch conditions operate on `buttonEvent`, use makeConditionLastUpdate()</span></div><div class="line">    <span class="comment">// to trigger on the last update time.</span></div><div class="line"></div><div class="line">    <span class="comment">// Some examples:</span></div><div class="line">    <a class="code" href="classhueplusplus_1_1_condition.html">hueplusplus::Condition</a> upPressed</div><div class="line">        = <a class="code" href="namespacehueplusplus_1_1sensors.html#a06dd5755779d2fc8df7108940319f7df">makeCondition</a>(switchSensor).eq(<a class="code" href="classhueplusplus_1_1sensors_1_1_z_l_l_switch.html#ae44c5a4e35ca3293fed52b03f395d951">hueplusplus::sensors::ZLLSwitch::c_UP_INITIAL_PRESS</a>);</div><div class="line">    <a class="code" href="classhueplusplus_1_1_condition.html">hueplusplus::Condition</a> buttonChanged = <a class="code" href="namespacehueplusplus_1_1sensors.html#a06dd5755779d2fc8df7108940319f7df">makeCondition</a>(switchSensor).dx();</div><div class="line"></div><div class="line">    <a class="code" href="classhueplusplus_1_1time_1_1_time_interval.html">hueplusplus::time::TimeInterval</a> interval(std::chrono::hours(12), std::chrono::hours(13));</div><div class="line">    <a class="code" href="classhueplusplus_1_1_condition.html">hueplusplus::Condition</a> updatedAtNoon = <a class="code" href="namespacehueplusplus_1_1sensors.html#aa674bacddb9d714ed65cf3c41306c8f5">makeConditionLastUpdate</a>(switchSensor).in(interval);</div></div><!-- fragment --><p> For generic sensors, the conditions must be created manually using the <a class="el" href="classhueplusplus_1_1_condition.html#a14c0d2560c50eb6dc36b44bb825d3c82">Condition</a> constructor with a proper address to the sensor state. </p>
</div></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.13
</small></address>
</body>
</html>