I did create some template sensors.
That is working fine.
But now I like to retamplate the sensor for the date time part.
I’m not very well used to do templating
I did create this sensor template:
These are the attributes I was working with from Developer Tools / States;
Local Time: Wed May 10 08:15:00 GMT+01:00 2023
Package: com.android.deskclock
Time in Milliseconds: 1683702900000
device_class: timestamp
icon: mdi:alarm
friendly_name: Matthew new p30 pro Next Alarm
As it happens the state actually shows the time in it, i would like to be able to extract it as to something like this 8:15 AM tomorrow, if that’s possible?
That will just return the 12-hour clock reading of whatever’s in that attribute, regardless of whether it’s in the past or future; and it’ll break if the attribute doesn’t match the format I’ve specified. In particular, I don’t know if the month is abbreviated (%b) or full (%B) because we’re in May and they’re the same.
Documentation is here, and here for strftime. You should probably provide a default value to strptime.
service: tts.cloud_say
data:
cache: false
entity_id: media_player.sitting_room
message: >-
Your alarm is set for {{
strptime(state_attr("sensor.matthew_new_p30_pro_next_alarm", "Local Time"),
"%a %b %d %H:%M:%S %Z%z %Y").strftime("%I:%M %p") }} which is in ...
I’m hoping to retrieve the amount of hours and minutes from ‘now’ to time of the next alarm, it shows the hours in this card but i can’t see where i can find the value to attempt to extract it.