Newbie here… I read the forum up and down and found many different ways to potentially solve this but I still can’t figure it out. In my configuration.yaml I have the following:
sensor:
- platform: template
sensors:
minutes_next_alarm_v:
friendly_name: "V Minutes Until Next Alarm"
unit_of_measurement: 'min'
icon_template: mdi:timer
value_template: "{{((states('sensor.v_s_21_next_alarm')|as_timestamp -
utcnow()|as_timestamp)/60)|round}}"
in the Developer Tools/Template to test it out it works correctly (shows the exact time until the next alarm), but the problem is once the alarm is activated (reached) on my phone, in the Template result I get this error:
ValueError: Template error: as_timestamp got invalid input 'unavailable' when rendering template '"{{((states('sensor.v_s_21_next_alarm')|as_timestamp - utcnow()|as_timestamp)/60)|round}}"' but no default was specified
I read in many posts that I should use default=0 but I have no idea where?!?
Why is this and how do I fix it (do I need to fix it or this is expected)?
You are using the old template yaml format. If you convert it to the new format (with template on top) you can set an availability template, so the sensor is unavailable when the’s no next alarm.
With the sensor as is, you could use a default parameter for as_timestamp to return the value that you want when there is no next alarm.
You should add it to your config.yaml, remove the old one and reload. And did you read the below remark that the entity is a bit different? your old one will still give the error, the new one should not due to the a ailability template.
I did add it to config.yaml and restarted and I get this error in the log:
2024-08-11 12:00:35.018 ERROR (MainThread) [homeassistant.config]
Invalid config for 'template' at configuration.yaml, line 14: required key 'state' not provided
Invalid config for 'template' at configuration.yaml, line 17: 'icon_template' is an invalid option for 'template', check: sensor->0->icon_template
Invalid config for 'template' at configuration.yaml, line 19: 'value_template' is an invalid option for 'template', check: sensor->0->value_template
Ah, yes, I didn’t check everything you put in, I assumed you checked the docs. The value template should be state, _template should be removed for the ico, maybe some more small changes. Best to check this for what the fields should be called:
why does it run at -11 min when the condition is between 20-30min before the alarm? Also the alarm on the phone was off at that time (it was turned off at 10:03)