hello I am trying to create a custom sensor in the config.yaml file.
it is
- name: BK Can Run Dryer
device_class: power
state_class: measurement
state: >
{% if (states ('sensor.????l_???_????') | float(0)*1000| int) <= 1500) and (states ('sensor.????_?????') | float(0)*1000 | int) >= 1500 %}
'yes 1'
{%else%}
'No'
{% endif %}
I want the sensor state to be yes or no so I can have a card that says yes or no when the arguments are right.
everything seems fine the yaml passes and the Jinja works.
but the issue is that the sensor does not show up in homeassistant.
Any help would be so grateful
Cheers
Thank you tom_I, I also had to take out the state class for it to finally work but thank you again.
I originally had two more and functions on the same line but it didnt seem to work with more than one and on the line. Is this how things work or is there a work around?
It’s unclear how many distinct entities are involved in the template’s comparison. Please post the template using meaningful entity_ids instead of sensor.????????.
You have some indention issues, you have a space in states(), it should not be states (), you don’t need to convert numbers to integers, there are more parentheses than you need, you could do with an availability template and some refinements to the layout to make it easier to read:
- name: BK Can Run Dryer
state: >
{% if states('sensor.1') | float(0) * 1000 < 0 and
states('sensor.2') | float(0) * 1000 <= 0 and
states('sensor.3') | float(0) * 1000 <= 1500 and
states('sensor.4') | float(0) * 1000 >= 1500 %}
yes 1
{% elif states('sensor.1') | float(0) * 1000 < 0 and
states('sensor.2') | float(0) * 1000 <= 0 and
states('sensor.3') | float(0) * 1000 >= 3500 and
states('sensor.4') | float(0) * 1000 >= 3500 %}
yes 2
{% else %}
No
{% endif %}
availability: >
{{ has_value('sensor.1') and
has_value('sensor.2') and
has_value('sensor.3') and
has_value('sensor.4') }}