Birthday count down notify everyday below 20

So these python_scripts appear to be stripped-down versions of mf_social’s comprehensive date_countdown.

@bhozar
Burningstone got it right.
That works in testing.

- alias: countdown_py_Notify
  initial_state: on
  trigger:
    - platform: state
      entity_id:
        - sensor.birthday_tina
        - sensor.birthday_adam
        - sensor.birthday_chloes
        - sensor.birthday_mum
  condition:
    condition: template
    value_template: "{{ trigger.to_state.state | int < 30 }}"
  action:
    # - service: notify.logfile2
    #   data_template:
    #     message: |-
    #       {%- for prop in trigger|sort if prop not in ['to_state', 'from_state'] -%}
    #         trigger.{{ prop }}: {{ trigger[prop] }}{{ '\n' }}
    #       {%- endfor -%}
          
    #       {%- for state in ['to_state', 'from_state'] if trigger[state] is defined -%}
    #         {{- '-' * 20 -}}{{ '\n' }}
    #         {%- for prop in ['state', 'entity_id', 'domain', 'object_id', 'name', 'last_updated', 'last_changed']|sort -%}
    #           trigger.{{ state }}.{{ prop }}: {{ trigger[state][prop] }}{{ '\n' }}
    #         {%- endfor -%}
    #         {%- for attr in trigger[state].attributes -%}
    #           trigger.{{ state }}.attributes.{{ attr }}: {{ trigger[state].attributes[attr] }}{{ '\n' }}
    #         {%- endfor -%}
    #       {%- endfor -%}
    - service: notify.logfile2
      data_template:
        message: "Don't forget {{ trigger.to_state.name }} in {{ trigger.to_state.state }} days. She ll be {{trigger.to_state.attributes.years | int +1 }} years old"

fyi, Thats the stuff you can work with

2020-08-07T17:23:43.727919+00:00 trigger.entity_id: sensor.birthday_mum
trigger.for: None
trigger.platform: state
--------------------
trigger.to_state.domain: sensor
trigger.to_state.entity_id: sensor.birthday_mum
trigger.to_state.last_changed: 2020-08-07 17:23:43.700812+00:00
trigger.to_state.last_updated: 2020-08-07 17:23:43.700812+00:00
trigger.to_state.name: Mum's Birthday
trigger.to_state.object_id: birthday_mum
trigger.to_state.state: 19
trigger.to_state.attributes.icon: mdi:calendar-star
trigger.to_state.attributes.unit_of_measurement: days
trigger.to_state.attributes.friendly_name: Mum's Birthday
trigger.to_state.attributes.nextoccur: 26/8/2020
trigger.to_state.attributes.birthday: 26/8/1950
trigger.to_state.attributes.years: 70
--------------------
trigger.from_state.domain: sensor
trigger.from_state.entity_id: sensor.birthday_mum
trigger.from_state.last_changed: 2020-08-07 17:23:03.154697+00:00
trigger.from_state.last_updated: 2020-08-07 17:23:03.154697+00:00
trigger.from_state.name: Mum's Birthday
trigger.from_state.object_id: birthday_mum
trigger.from_state.state: 18
trigger.from_state.attributes.icon: mdi:calendar-star
trigger.from_state.attributes.unit_of_measurement: days
trigger.from_state.attributes.friendly_name: Mum's Birthday
trigger.from_state.attributes.nextoccur: 25/8/2020
trigger.from_state.attributes.birthday: 25/8/1950
trigger.from_state.attributes.years: 70
2020-08-07T17:23:43.748680+00:00 Don't forget Mum's Birthday  in 19 days. She ll be 71 years old

lol, sry 123. wrong reply button

1 Like

@Burningstone and @123 Lol yes you are right my apologises forgot about the trigger time set to trigger:
trigger:
- platform: time
at: ‘00:00:01’

Changed that to test worked like a charm . Thank You both

@Burningstone and @123 been test this for a few days and it only triggers on the first sensor that is below 30 . So if i set tina and mum to be less then 30 days left I only get a message for Tina because she is first in the list. Any ideas?

1 Like

@Underknowledge Been test this for a few days and it only triggers on the first sensor that is below 30 . So if i set tina and mum to be less then 30 days left I only get a message for Tina because she is first in the list. Any ideas?. I see you started to write a solution ! did this work ?

When more than one entity is less than 30 days, and only the first entity is used for the notification, is there a warning message in the log (saying something about the fact that the automation’s action is already executing)?

If so, you want to try adding mode: queued to the automation.

Yes it says: Message Reminder Birthday: Already running 13:24:00 – Automation (WARNING). Hows the best way to add Queued Never used it before Thank!

So what’s happening is that the automation is triggered twice at virtually the same time. The first trigger for Tina executes the action but the second trigger for mum cannot because the action is busy performing the notification for tina. That’s because the default is mode: single.

By changing the mode to queued, mum’s notification will occur right after Tina’s notification is completed.

2 Likes

Cheers got it just tried it out seems to work. Thank you for that. Just reading about Queued and max number of runs . If i am reading this right I set this to the amount of birthdays I have . Thanks again

You can also try setting mode to parallel. This would attempt to notify Tina and mum concurrently (i.e. in parallel) as opposed to one after the other.

2 Likes