I have a switch for turning on/off my desktop computer. On/off works fine. I have a value_template for setting it’s status based on a device_tracker through the ping service. The device_tracker works fine (ie. it is set to home/not_home if the computer is on/away). However, the status of the switch is not changed accordingly. If I enter the same snippets in Template it works fine. Can’t figure out what I’m doing wrong here.
I have also tried with, among other things, value_template:'{{ states("device_tracker.meru") == "home" }}' which also works fine in Template, but not for this value_template. I’ve also tried with if ... then templates, which also has worked out fine in Template, but – you got it – not here. Also tried all different variations of single-/double quotes for value_template that I’ve been able to think of, as well as using the >- format instead of having it on the same line. So far, nothing has helped. :-S
looks like that value template requires a command_state. I looked into it and I don’t see it calling the normal template functionality. It appears to only evaluate against whatever is placed into the command_state.
You may be better off making a template switch. with 2 shell commands. One for on, one for off:
I’m having more or less similar issue.
In my case, I have a MySensors node connected to a Bosch gas heater and reading it’s data using OpenTherm. Since in MySensors API there’s no specialised sensor for water gas heater yet, I present the node as a binary door sensor. And are multiple children in the node, so i have entities named binary_sensor.boiler_monitor_2_0 and binary_sensor.boiler_monitor_2_2 (0 is for flame state, 2 is for heating state, 1 is reserved for DHW temp).
What I am trying to achieve is just change rename the ‘door sensor’ outputs to be more boiler-specific, just as mentioned in the docs: https://www.home-assistant.io/components/sensor.template/#renaming-sensor-output
I use a binary_sensor template, since I wanted to use an icon. The config is:
- platform: template
sensors:
flame_state:
friendly_name: 'Boiler flame'
icon_template: >-
{% if is_state_attr('binary_sensor.boiler_monitor_2_0', 'V_TRIPPED', 'off') %}
mdi:close-circle
{% else %}
mdi:mdi-fire
{% endif %}
value_template: >-
{% if is_state_attr('binary_sensor.boiler_monitor_2_0', 'V_TRIPPED', 'off') %}
off
{% else %}
on
{% endif %}
The issue is the same, if I enter this snippet in the Templates section of dev-tools, I can see that value_template is populated accordingly, but in the frontend the flame_state entity is always off.
This is not similar to @krissen’s issue at all. It may seem like it, but it’s not.
does the binary_sensor.boiler_monitor_2_0 have a V_TRIPPED attribute? The likely hood of this object having an all caps attribute is slim to none. Attributes are dictionaries, and home assistant tries to make all attributes lower case.
are you sure the result of this attribute is on/off?
Regular sensor templates support icon_templates as well. Not just binary sensors.
This may be causing problems because you are returning a string. Both strings when empty are considered false. Strings when populated are considered true. You are providing the template with 2 trues. I’d expect it to always be on.
This is what your value template should look like (assuming that attribute is correct):
I don’t get it. {{...}} is Jinja’s syntax for value interpolation into the template. This expression will just yield “True”. I’ve tried putting it into the configuration file, but this doesn’t changed the result.