Hi, I updated home assistant and then started getting tons of errors related to sensors. I tried splitting my sensors to a separate page and cleared the errors, however, for some reason the value doesn’t seem to be coming across anymore but oddly the icon does. Here’s what is in my configuration.yaml:
binary_sensor:
# C43 status
- platform: template
sensors: !include sensor.yaml
My sensor.yaml file looks like this:
#C43 Doors status
sensor.car_door_open:
friendly_name: Any Car Door Open
value_template: >-
{% if is_state_attr('sensor.c43_lock', 'doorStatusOverall', '1')%}
Closed
{% else %}
Open
{% endif %}
icon_template: >
{% if is_state_attr('sensor.c43_lock', 'doorStatusOverall', '1')%}
mdi:door-closed
{% else %}
mdi:door-open
{% endif %}
When I pull the value sensor.car_door_open I get OFF, which isn’t right. As I said, for some reason the icon shows correctly in the UI. Any thoughts please?
You are configuring it under the binary_sensor top-level key. Generally, binary sensors are either ‘off’ or ‘on’. If you want the front end states representation of a door, you need to add a device class.
TBH, as was noted above I’m surprised it ever worked as it was.
binary sensors are only ever on or off and will by definition never show open or closed just solely based on the value_template contents. the template must return either true/on or false/off for the binary sensor to indicate correctly.
also I’m surprised you didn’t get some kind of slug error based on the sensor entity_id you created because it contains a ‘.’ in the id.
I can see this being one of two things…
either you mistakenly had the original sensor under the “sensor:” domain key and not the “binary_sensor:” domain. Along with you likely changing the sensor id to add the “sensor.” part.
or
HA started using more strict checking of the rendered value of the template.
To fix it either change the domain from binary_sensor to sensor and get rid of the ‘sensor.’ from the sensor id.
or change the binary sensor to use the modern format, fix the template to only return true or false and add the state_class of ‘door’ to get it to show the correct indication in the front end (behind the scenes in the states page it will still only be on or off and never open or closed)
You are correct. I accidentally added the sensor. when I was copying it over. However, after making some updates now it appears to be completely broken. I also searched around for value_templates and can’t seem to find any pertinent information. I’m trying pull attributes from an entity sensor.c43_lock. The state attributes from this sensor are:
car: AMG43
vin: MyVIN
retrievalstatus: VALID
timestamp: “2023-12-02T06:31:00”
doorstatusrearright: false
doorstatusfrontright: false
engineHoodStatus: false
doorStatusOverall: “1”
doorstatusrearleft: false
doorlockstatusrearright: false
doorlockstatusvehicle: “2”
doorlockstatusdecklid: false
sunroofstatus: “0”
doorlockstatusgas: false
decklidstatus: false
doorlockstatusfrontright: false
doorstatusfrontleft: false
doorLockStatusOverall: “0”
doorlockstatusrearleft: false
doorlockstatusfrontleft: false
icon: mdi:car-key
friendly_name: AMG43 Lock
#C43 Doors status
car_door_open:
friendly_name: Any Car Door Open
value_template: >-
{% if is_state_attr('sensor.c43_lock', 'doorStatusOverall', '1')%}
Closed
{% else %}
Open
{% endif %}
icon_template: >
{% if is_state_attr('sensor.c43_lock', 'doorStatusOverall', '1')%}
mdi:door-closed
{% else %}
mdi:door-open
{% endif %}
As I stated, now none of the information is coming over and I can’t figure out why and can’t find any documentation on value_templates anymore. Is there another way to extract the information out of this entity to be used as a sensor? And honestly, I’m not even sure it needs to be used as a sensor, but can I extract the information out to show in the UI and in automations? Thanks!
Looks like you’re getting the old and new template syntax confused in addition to trying to split the config. (the two sets of keywords that wiil help you search for help on this one BTW, new template and split config)
This thread will probably help
Also this will be far easier if you…
First get the template working correctly in configuration.yaml using the new template configuration for a binary_sensor (its the simplest and most native way - what you have is indeed a binary sensor - only two states active or not) let the UI handle the fact that it’s a door and should use door stuff by declaring the device class.
Then, once that’s working split the config
(TL ;Dr: the two syntaxes you are mixing are added under two completely different keys, one tenplate: and the other binary_sensor: so fix that first, then you can work on the split again)
And do you ‘need to?’ that’s entirely up to you but if it’s mine yes. First this seems reusable, second fixing it will teach you how to differ between old and new template sensor syntaxes and how to properly split config)
Ok, I figured it out. Using the template editor helped me realize that the templates were working correctly the whole time. The issue was that I had them as binary_sensors in the UI. When I updated it from binary_sensor to sensor in the configuration.yaml file everything got messed up. It’s all working correctly now, thanks for the help!