Hi all.
Ive been banging my head against this for ages on and off – i think ive been looking at it for too long and i am now missing something obvious.
Ive tried a few different combos (along the lines of states(‘sensor.name’) but i just cant seem to get anything to work.
The error is:
Failed config
sensor.template:
- Invalid config for [sensor.template]: invalid template (TemplateSyntaxError: unexpected ‘)’) for dictionary value @ data[‘sensors’][‘air_status’][‘value_template’]. Got ‘{% if states.sensor.thing|int < 34 %}\n Very Good\n{% elif states.sensor.thing|int < 67) %}\n Good\n{% elif states.sensor.thing|int < 100 %}\n Fair\n{% elif states.sensor.thing|int < 150 %}\n Poor\n{% elif states.sensor.thing|int < 200 %}\n Very Poor\n{% endif %}\n Hazardous’. (See ?, line ?). Please check the docs at https://home-assistant.io/integrations/template/
Did you save? The error message in your template is missing characters. Based on your post, you’re either looking at the wrong spot, you didn’t save your changes, or the error is old/out-of-date:
OK, thanks, it was supposed to be unique_id so I changed entity_id to that, however same error as previous.
I have saved it and it says saved however I changed a string in the same file and it did not update in the error message. Any idea how/why that would happen?
And it’s not an old error, the last logged time == now
After modifying the Template Sensor’s configuration, you must either execute Reload Template Entities or restart Home Assistant. If you are doing that and there is still a discrepancy between what you edited and what Home Assistant is actually using then it’s due to what Petro said.
I was definitely updating the right file and restarting HA. After reboot, I can now get it working. Thanks, not sure why the file editor was not saving properly.
Like Petro said, that is needed here and should have worked. However, your system is a mystery to me now that you claim the only way your Template Sensor changes in configuration.yaml are recognized is after rebooting the server. That shouldn’t be at all necessary and a simple Reload Template Entities, or restart, should do the trick.
Thanks both, appreciate your help. Yeah I tried with "23" too and updated unique_id as petro said…still unavailable, still saying “does not have a unique ID”
So this is currently my config for that sensor:
sensor:
- platform: template
sensors:
front_door_state:
friendly_name: 'Front Door state'
unique_id: front_door_state
value_template: >-
{%- if is_state('sensor.front_door_access_control', '23') -%}
Closed
{%- else -%}
Open
{%- endif -%}
Previously I have had changes in the config work from a restart, it is just when doing this sensor that I’ve had issues.
That said, I do have a couple of lingering error messages, I think from another integration that I didn’t get round to diagnosing, but I don’t think they would be affecting this sensor. I’m not sure how to troubleshoot that further as the messages are very vague:
Logger: homeassistant.helpers.check_config
Source: components/script/config.py:44
First occurred: 17:53:36 (7 occurrences)
Last logged: 18:28:17
Unexpected error validating config
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/check_config.py", line 145, in async_check_ha_config_file
await config_validator.async_validate_config( # type: ignore
File "/usr/src/homeassistant/homeassistant/components/script/config.py", line 44, in async_validate_config
for object_id, cfg in config[DOMAIN].items():
AttributeError: 'NodeListClass' object has no attribute 'items'
And
Logger: homeassistant.components.hassio
Source: components/hassio/__init__.py:420
Integration: Home Assistant Supervisor (documentation, issues)
First occurred: 17:53:36 (5 occurrences)
Last logged: 18:28:17
Unexpected error calling config validator: 'NodeListClass' object has no attribute 'items'
I’m beginning to think you have a configuration error. Any additions/modifications you make are ignored by Home Assistant until you fix that configuration error. That would explain why the mods you make to the Template Sensor aren’t being used by Home Assistant (until you give it no choice when you reboot the server).
Execute Configuration > Server Controls > Check Configuration and see what it has to say.