diff --git a/atom.xml b/atom.xml index 5a1fd9067c..26bbf9e5c7 100644 --- a/atom.xml +++ b/atom.xml @@ -4,7 +4,7 @@
# Example configuration.yaml entry binary_sensor: - platform: template - sensors: - sun_up: - value_template: '{{ states.sun.sun.attributes.elevation > 0}}' - friendly_name: 'Sun is up' + - platform: template + sensors: + sun_up: + value_template: '{{ states.sun.sun.attributes.elevation > 0}}' + friendly_name: 'Sun is up'
sensor: - platform: template - sensors: - furnace_on: - value_template: {{ states.sensor.furnace.state > 2.5 }} - friendly_name: 'Furnace Running - sensor_class: heat + - platform: template + sensors: + furnace_on: + value_template: {{ states.sensor.furnace.state > 2.5 }} + friendly_name: 'Furnace Running + sensor_class: heat
Some movement sensors and door/window sensors will apear as a switch. By using a template binary sensor, the switch can be displayed as a binary sensors. The original switch can then be hidden by customizing.
+Some movement sensors and door/window sensors will appear as a switch. By using a template binary sensor, the switch can be displayed as a binary sensors. The original switch can then be hidden by customizing.
binary_sensor: - platform: template - sensors: - movement: - value_template: "{{ states.switch.movement.state == 'on' }}" - sensor_class: motion - door: - value_template: "{{ states.switch.door.state == 'on' }}" - sensor_class: opening + - platform: template + sensors: + movement: + value_template: "{{ states.switch.movement.state == 'on' }}" + sensor_class: motion + door: + value_template: "{{ states.switch.door.state == 'on' }}" + sensor_class: opening
If you are using a DHT sensor and a NodeMCU board (esp8266), you can retrieve temperature and humidity with a MQTT sensor. A code example can be found here. A regular MQTT message from this example looks like this:
+ +office/sensor1
+ {
+ "temperature": 23.20,
+ "humidity": 43.70
+ }
+
+
+Then use this configuration example to extract the data from the payload:
+ +# Example configuration.yml entry +sensor 1: + platform: mqtt + state_topic: 'office/sensor1' + name: 'Temperature' + unit_of_measurement: '°C' + value_template: '' + +sensor 2: + platform: mqtt + state_topic: 'office/sensor1' + name: 'Humidity' + unit_of_measurement: '%' + value_template: '' +
Details about the API are available in the OpenWeatherMap documentation.
+Details about the API are available in the OpenWeatherMap documentation.
Only metric measurements are supported at the moment.
diff --git a/components/sensor.template/index.html b/components/sensor.template/index.html index 19f1965c42..99c47830cc 100644 --- a/components/sensor.template/index.html +++ b/components/sensor.template/index.html @@ -96,14 +96,14 @@# Example configuration.yaml entry sensor: - platform: template - sensors: - solar_angle: - value_template: '{{ states.sun.sun.attributes.elevation }}' - friendly_name: 'Sun angle' - unit_of_measurement: 'degrees' - sunrise: - value_template: '{{ states.sun.sun.attributes.next_rising }}' + - platform: template + sensors: + solar_angle: + value_template: '{{ states.sun.sun.attributes.elevation }}' + friendly_name: 'Sun angle' + unit_of_measurement: 'degrees' + sunrise: + value_template: '{{ states.sun.sun.attributes.next_rising }}'
sensor: - platform: template - sensors: - solar_angle: - value_template: '{{ "%+.1f"|format(states.sun.sun.attributes.elevation) }}' - friendly_name: 'Sun Angle' - unit_of_measurement: '°' + - platform: template + sensors: + solar_angle: + value_template: '{{ "%+.1f"|format(states.sun.sun.attributes.elevation) }}' + friendly_name: 'Sun Angle' + unit_of_measurement: '°'
sensor: - platform: template - sensors: - sun_state: - value_template: '{% if is_state("sun.sun", "above_horizon") %}up{% else %}down{% endif %}' - friendly_name: 'Sun state' + - platform: template + sensors: + sun_state: + value_template: '{% if is_state("sun.sun", "above_horizon") %}up{% else %}down{% endif %}' + friendly_name: 'Sun state'
sensor: - platform: template - sensors: - glances: - value_template: '{% if is_state("sensor.process_glances", "off") %}not running{% else %}running{% endif %}' - friendly_name: 'Glances' + - platform: template + sensors: + glances: + value_template: '{% if is_state("sensor.process_glances", "off") %}not running{% else %}running{% endif %}' + friendly_name: 'Glances'
The Binary template sensor is the one in similar cases if you prefer to see an icon instead of text.
-This example shows a multiple line template with and if test. It looks at a sensing switch and shows on/off in the frontend. It disables warnings to avoid log messages where the switch it depends on isn’t loaded yet.
+This example shows a multiple line template with and if test. It looks at a sensing switch and shows on/off in the frontend.
sensor: - platform: template - sensors: - kettle: - friendly_name: 'Kettle' - value_template: >- - {%- if is_state("switch.kettle", "off") %} - off - {% elif states.switch.kettle.attributes.kwh < 1000 %} - standby - {% elif is_state("switch.kettle", "on") %} - on - {% else %} - failed - {%- endif %} + - platform: template + sensors: + kettle: + friendly_name: 'Kettle' + value_template: >- + {%- if is_state("switch.kettle", "off") %} + off + {% elif states.switch.kettle.attributes.kwh < 1000 %} + standby + {% elif is_state("switch.kettle", "on") %} + on + {% else %} + failed + {%- endif %} - warnings: Off + next_sensor: + [...]
(please note the blank line to close the multi-line template)
++Please note the blank line to close the multi-line template. +
sensor: - platform: template - sensors: - transmission_down_speed_kbps: - value_template: '{{ states.sensor.transmission_down_speed.state | multiply(1024) }}' - friendly_name: 'Transmission Down Speed' - unit_of_measurement: 'kB/s' - transmission_up_speed_kbps: - value_template: '{{ states.sensor.transmission_up_speed.state | multiply(1024) }}' - friendly_name: 'Transmission Up Speed' - unit_of_measurement: 'kB/s' + - platform: template + sensors: + transmission_down_speed_kbps: + value_template: '{{ states.sensor.transmission_down_speed.state | multiply(1024) }}' + friendly_name: 'Transmission Down Speed' + unit_of_measurement: 'kB/s' + transmission_up_speed_kbps: + value_template: '{{ states.sensor.transmission_up_speed.state | multiply(1024) }}' + friendly_name: 'Transmission Up Speed' + unit_of_measurement: 'kB/s'
# Example configuration.yaml entry switch: - platform: template + - platform: template switches: - skylight: - friendly_name: 'Skylight' - value_template: '{{ is_state('sensor.skylight', 'on') }}' - turn_on: - service: switch.turn_on - entity_id: switch.skylight_open - turn_off: - service: switch.turn_on - entity_id: switch.skylight_close + skylight: + friendly_name: 'Skylight' + value_template: '{{ is_state('sensor.skylight', 'on') }}' + turn_on: + service: switch.turn_on + entity_id: switch.skylight_open + turn_off: + service: switch.turn_on + entity_id: switch.skylight_close
If you are using the state of a platform that takes extra time to load, the template switch may get an ‘unknown’ state during startup. This results in error messages in your log file until that platform has completed loading. If you use is_state() function in your template, you can avoid this situation. For example, you would replace ‘{{ states.switch.source.state }}’ with this equivalent that returns true/false and never gives an unknown result:
-‘{{ is_state(‘switch.source’, ‘on’) }}’{% stendraw %}
In this section you find some real life examples of how to use this switch.
-This example shows a switch that copies another switch.
switch: - platform: template + - platform: template switches: - copy: - value_template: {% raw %}'{{ is_state('switch.source', 'on') }}' - turn_on: - service: switch.turn_on - entity_id: switch.source - turn_off: - service: switch.turn_off - entity_id: switch.source + copy: + value_template: '{{ is_state('switch.source', 'on') }}' + turn_on: + service: switch.turn_on + entity_id: switch.source + turn_off: + service: switch.turn_off + entity_id: switch.source
switch: - platform: template + - platform: template switches: - blind: - friendly_name: 'Blind' - value_template: '{{ state }}' - turn_on: - service: switch.toggle - entity_id: switch.blind_toggle - turn_off: - service: switch.toggle - entity_id: switch.blind_toggle + blind: + friendly_name: 'Blind' + value_template: '{{ state }}' + turn_on: + service: switch.toggle + entity_id: switch.blind_toggle + turn_off: + service: switch.toggle + entity_id: switch.blind_toggle
switch: - platform: template + - platform: template switches: - skylight: - friendly_name: 'Skylight' - value_template: '{{ is_state('sensor.skylight.state', 'on') }}' - turn_on: - service: switch.turn_on - entity_id: switch.skylight_open - turn_off: - service: switch.turn_on - entity_id: switch.skylight_close + skylight: + friendly_name: 'Skylight' + value_template: '{{ is_state('sensor.skylight.state', 'on') }}' + turn_on: + service: switch.turn_on + entity_id: switch.skylight_open + turn_off: + service: switch.turn_on + entity_id: switch.skylight_close