Site updated at 2017-10-30 21:14:39 UTC

This commit is contained in:
Travis CI 2017-10-30 21:14:39 +00:00
parent 73b9346a6c
commit a7127854a2
27 changed files with 83 additions and 90 deletions

View file

@ -75,11 +75,14 @@
</header>
<hr class="divider">
<h3><a class="title-link" name="ios-devices" href="#ios-devices"></a> iOS Devices</h3>
<p>If you have a device running iOS (iPhone, iPad, etc), The <a href="/components/device_tracker.icloud/">iCloud</a> is gathering various details about your device including the battery level. To display it in the Frontend use a <a href="/components/sensor.template/">template sensor</a>.</p>
<p>If you have a device running iOS (iPhone, iPad, etc), The <a href="/components/device_tracker.icloud/">iCloud</a> is gathering various details about your device including the battery level. To display it in the Frontend use a <a href="/components/sensor.template/">template sensor</a>. You can also use the icon template option to create a dynamic icon that changes with the battery level.</p>
<div class="language-yaml highlighter-rouge"><pre class="highlight"><code><span class="s">sensor</span><span class="pi">:</span>
<span class="pi">-</span> <span class="s">platform</span><span class="pi">:</span> <span class="s">template</span>
<span class="s">sensors</span><span class="pi">:</span>
<span class="s">battery_iphone</span><span class="pi">:</span>
<span class="s">friendly_name</span><span class="pi">:</span> <span class="s">iPhone Battery</span>
<span class="c1"># "entity_id:" ensures that this sensor will only update when your device tracker does.</span>
<span class="s">entity_id</span><span class="pi">:</span> <span class="s">device_tracker.iphone</span>
<span class="s">unit_of_measurement</span><span class="pi">:</span> <span class="s1">'</span><span class="s">%'</span>
<span class="s">value_template</span><span class="pi">:</span> <span class="pi">&gt;-</span>
<span class="no">{%- if states.device_tracker.iphone.attributes.battery %}</span>
@ -87,6 +90,16 @@
<span class="no">{% else %}</span>
<span class="no">{{ states.sensor.battery_iphone.state }}</span>
<span class="no">{%- endif %}</span>
<span class="no">icon_template: &gt;</span>
<span class="no">{% set battery_level = states.sensor.battery_iphone.state|default(0)|int %}</span>
<span class="no">{% set battery_round = (battery_level / 10) |int * 10 %}</span>
<span class="no">{% if battery_round &gt;= 100 %}</span>
<span class="no">mdi:battery</span>
<span class="no">{% elif battery_round &gt; 0 %}</span>
<span class="no">mdi:battery-{{ battery_round }}</span>
<span class="no">{% else %}</span>
<span class="no">mdi:battery-alert</span>
<span class="no">{% endif %}</span>
</code></pre>
</div>
<p>The <code class="highlighter-rouge">else</code> part is used to have the sensor keep its last state if the newest <a href="/components/device_tracker.icloud/">iCloud</a> update doesnt have any battery state in it (which happens sometimes). Otherwise the sensor will be blank.</p>