since the next_alarm entity on Android HA app has been provided recently, I wanted to switch my alarm templates from using Hassalarm to this new method.
When testing this in the template editor I experienced some interesting behaviour.
Next Alarm Companion App:
current time : {{now().strftime("%a %h %d %H:%M %Z %Y")}}
alarm time : {{(((state_attr('sensor.pixel_4_xl_next_alarm', 'Time in Milliseconds') | int / 1000) - 0*60 ) | timestamp_custom('%a %h %d %H:%M %Z %Y')) }}
triggered: : {{now().strftime("%a %h %d %H:%M %Z %Y") == (((state_attr('sensor.pixel_4_xl_next_alarm', 'Time in Milliseconds') | int / 1000) - 11*60 ) | timestamp_custom('%a %h %d %H:%M %Z %Y')) }}
The result looks this:
Next Alarm Companion App:
current time : Mon Nov 02 13:19 CET 2020
alarm time : Mon Nov 02 16:42 CET 2020
triggered: : False
Sometimes when I set my smartphone alarm clock to a specific time like 16:43, the template shows 16:42. But sometimes it uses the correct time in minutes.
I can’t really see a pattern besides the fact, when it happens, the templates is set to 1 minute before the actual time which has been set up on the phone.
I moved it to the companion app forum.
However, when this issue occurs the time of the app sensor show the correct time. It seems to be the sensor entity on the server which receives the wrong time.
what alarm app are you guys using? Some alarm apps are known for sending incorrect time. All the app does is take whatever time Google sends to us and we send it back to HA. There is no data manipulation going on.
I’m using the stock android clock. In the HA companion App under sensors the next alarm matches the android alarm but the alarm time being shown in HA has an offset.
e.g. I set the alarm on android to 21:45.
under sensors in the HA companion app 2020-11-03T20:45:00.000Z is shown. That’s probably CET.
in HA under developer tools, this code
{{(((state_attr('sensor.pixel_4_xl_next_alarm', 'Time in Milliseconds') | int / 1000) - 0*60 ) | timestamp_custom('%a %h %d %H:%M %Z %Y')) }}
So the timestamp provided is that which your device reports as local time. That is what you see in time in milliseconds, that is pure raw data from the android API. If you are referring to what the Front end is displaying to you then that is entirely different from what the app provides. We only take the system provided time and convert the state to UTC format since that is what the front end expects and the attributes remain as local time to help the user with less conversions.
ok. But why is there an offset between the next alarm entity and the information the companion app provides? Is there maybe an error or rounding error in code mentioned above?
More than likely its a jinja issue. One thing we added recently to the beta version of the app is sleep as android integration…The sleep as android app has some neat events that may do away with some of this templating. For example you can tell when an alarm was triggered, snoozed or even dismissed. No need for templating or looking at the time etc…
This is raw data from google as I mentioned up above. We don’t change it and only convert to date/time in UTC format as you can see in the code linked up above.
So, that means the timestamp is being shown incorrectly while the template to trigger the condition should be accurate in case we leave out the timestamp function, right?