Hi,
i’m trying to use the “value_template” on a binary sensor (Nest thermostat) but i cannot see the custom value set by me.
In my configuration.yaml i’ve added this:
binary_sensor: !include_dir_merge_list binary_sensor
After this, in the folder “binary_sensor”, i’ve created a new yaml file with these lines:
- platform: template
sensors:
nest_thermostat_state:
friendly_name: 'State'
entity_id:
- binary_sensor.entryway_thermostat_online
value_template: >-
{%- if is_state("binary_sensor.entryway_thermostat_online", "on") -%}
Online
{%- else -%}
Offline
{%- endif %}
Unfortunately, in my custom binary sensor binary_sensor.nest_thermostat_state I see the default values “on” and “off”. Why I cannot see the values “Online” or “Offline”?
Can you help me please? What i’m doing wrong?
rpitera
(Robert Pitera)
February 3, 2017, 9:21pm
2
Try single quotes in the value template:
{%- if is_state('binary_sensor.entryway_thermostat_online', 'on') -%}
Thanks for reply!
I tried to use single quotes in the value template but same result…
rpitera
(Robert Pitera)
February 3, 2017, 9:30pm
4
I’m using a similar scheme to rename some devices I track, but my formatting is a little different from yours:
- platform: template
sensors:
epsonprinter:
value_template: "{% if is_state('device_tracker.epson3e7694fiosrouterhome', 'home') %}on{% else %}off{% endif %}"
I don’t think you need the entity_id: lines.
This is my new code as suggest by you…but same result…I don’t understand!
- platform: template
sensors:
nest_thermostat_state:
friendly_name: 'State'
value_template: "{% if is_state('binary_sensor.entryway_thermostat_online', 'on') %}Online{% else %}Offline{% endif %}"
rpitera
(Robert Pitera)
February 3, 2017, 9:42pm
6
It could be how you did the include. What happens if you copy the value template and paste it into the template tester in the dev panel?
I tried to paste the template in the template tester and it’s works! The same condition return “Offline” in this case…
I tried with double quotes and single quotes…in the template tester it works but in my yaml doesn’t works!
rpitera
(Robert Pitera)
February 3, 2017, 9:49pm
8
Check to make sure your using the right include method then. I have a lot of trouble with figuring out which method is which myself.
I’ve added the template within the configuration.yaml but the result is the same…
binary_sensor:
- platform: template
sensors:
nest_thermostat_state:
friendly_name: 'State'
value_template: "{% if is_state('binary_sensor.entryway_thermostat_online', 'on') %}Online{% else %}Offline{% endif %}"
It seems a bug…i don’t understand! I’m following the guide Template Binary Sensor but it seems doesn’t works very well…
PtP
(Mike)
February 3, 2017, 10:49pm
10
If you are trying to change the output of the entity it would just be a template sensor.
or try using the elif… I think there was a post about using them both…
mc_garage_state:
value_template: '{% if is_state("binary_sensor.garage_controller", "on") %}Open{% elif states.binary_sensor.garage_controller, "off" %}Closed{% else %}Check Connection{% endif %}'
You’re right…with template sensor should works…but i want use “sensor_class” and other features provided by template binary sensor…why i can’t use it? I’m sad
I just tried with elif…but same result!
PtP
(Mike)
February 4, 2017, 12:06am
12
Son of a!! Lol
Why do you want to use sensor_class:?
I would like use sensor_class because i want the icons provided by hass (better management of on/off states).
And I like the order!!
But if there are not ant solutions…i will proceed with classic sensor templates…
PtP
(Mike)
February 4, 2017, 12:18am
14
Cool! You can change the icon using customize: though.
can i manage the yellow icons with customize and sensor template?
PtP
(Mike)
February 4, 2017, 4:59am
16
To be honest you should never have to look at your phone, tablet, or PC.
Best of Luck!
rpitera
(Robert Pitera)
February 4, 2017, 3:37pm
17
You can choose a single custom icon. That icon will change to yellow to indicate the on state.