SOLVED: Compare two "next alarm" phone sensors and update an helper

Edit: I think I got it. First I didn’t need “data_template:” only “data:” then I added a space between the colon and the carot in “datetime: >-”.

Thank you ferri and paddy for your help. I coppeid this directly from the code from the marked solution.

action:
  - service: input_datetime.set_datetime
    target:
      entity_id: input_datetime.last_alarm
    data_template: >-
      datetime:>- 
        {% if 'sensor.guy_s_phone_next_alarm' > 'sensor.girl_s_phone_next_alarm' %}
          {{ as_timestamp(states('sensor.girl_s_phone_next_alarm')) | timestamp_custom('%Y-%m-%d %H:%M:00') }}
        {%- elif 'sensor.guy_s_phone_next_alarm' <= 'sensor.girl_s_phone_next_alarm' %}
          {{ as_timestamp(states('sensor.guy_s_phone_next_alarm')) | timestamp_custom('%Y-%m-%d %H:%M:00') }}
        {%- endif %}
    data:
      datetime: >- 

Should look like this.

To explain:

  • the > makes for a multi-line YAML. So you have either one line encapsulated in " or multi-line with >
  • the dash behind removes all following white space in a multi-line YAML.

Just to note: data_template should still work, but it is deprecated and shouldn’t be used anymore. :slight_smile:

Thanks for the info about “data_template”. I not often read the updated notes for the news version.

It will be simply replace by “data” ?
If so, do you think it is possible use “find and replace” (with note+ app for example) in all my automation.yaml? It will work?

Thanks

That should work. :slight_smile: On the other hand, do a search first, there might be less occurrences than you think. But this will only work in the direction data_templatedata not the other way around! :wink:

So, the usual recommendation: do a backup right before you do the change, so you can easily go back by restoring!!! :slight_smile: Just saying…

Of course a backup will be done :+1:
It is my lifeline since I’m not a real programmer :rofl:
Thanks for your help.
Have a good one

1 Like