If I understand correctly, this is what you want to do with a template sensor…
sensor:
- platform: template
sensors:
sensor_image:
entity_id:
- binary_sensor.left
- binary_sensor.right
value_template: >-
{% set left = states.binary_sensor.left.state %}
{% set right = states.binary_sensor.right.state %}
{% if left == "off" and right == "off" %}
{% set n = "0" %}
{% elif left == "on" and right == "off" %}
{% set n == "1" %}
{% elif left == "off" and right == "on" %}
{% set n == "2" %}
{% else %}
{% set n == "3" %}
{% endif %}
{{ ["image", n, ".png"] | join("") }}
Invalid config for [sensor.template]: invalid template (TemplateSyntaxError: expected token 'end of statement block', got 'string') for dictionary value @ data['sensors']['sensor_image']['value_template']. Got '{% set left = states.binary_sensor.left.state %} {% set right = states.binary_sensor.right.state %} {% if is_state(\'left\', \'off\') and is_state\'right\', \'off\' %}\n {% set n = "0" %}\n{% elif left == "on" and right == "off" %}\n {% set n == "1" %}\n{% elif left == "off" and right == "on" %}\n {% set n == "2" %} \n{% else %}\n {% set n == "3" %}\n{% endif %} {{ ["image", n, ".png"] | join("") }}'. (See ?, line ?). Please check the docs at https://home-assistant.io/components/sensor.template/
As I can see it, it’s the ‘set’ lines that it complains about?
Ah I had an extra = sign in a few places. This is what happens when I write code at night and don’t test. Try this
sensor:
- platform: template
sensors:
sensor_image:
entity_id:
- binary_sensor.left
- binary_sensor.right
value_template: >-
{% set left = states.binary_sensor.left.state %}
{% set right = states.binary_sensor.right.state %}
{% if left == "off" and right == "off" %}
{% set n = "0" %}
{% elif left == "on" and right == "off" %}
{% set n = "1" %}
{% elif left == "off" and right == "on" %}
{% set n = "2" %}
{% else %}
{% set n = "3" %}
{% endif %}
{{ ["image", n, ".png"] | join("") }}
Are you sure the payload data for the sensors is “on” and “off”? If not, that would explain why none of the conditions are met and the result is always set to 3.
I think I found out why, the state is set to ON and not on etc.
Unfortunately I have to wait to test it out until I get to my computer again, I’m currently volunteering as an official in a 306 km amateur cycle race called Sjælland Rundt
Yes, exactly, that was my thought as well, and also what I tried to illustrate in the pseudo code I wrote.
Oh, that looks very nice the way you did that, and I think I can see how to show the image as well
Next step is temperatures etc.
I haven’t figure out how to use the sensor value for the picture, so for now, I’ve just changed it to 0-3 as value, and then a state picture in the card.