Miicroo/ha-birthdays

Telegram notifications for all birthdays on a day.

Closed this issue ยท 12 comments

Hi!
First if all, thanks for this integration!
I have a problem with sending notifications when there are more than 1 birthday on a day, I only get one message. How can I fix this?
I created your sensor, added birthdays and this is my automation:

- id: birthday_reminder
  alias: Send notification for birthday
  trigger:
    platform: time
    at: "08:00:00"
  condition:
    condition: state
    entity_id: sensor.next_birthday
    state: 0
  action:
    - service: telegram_bot.send_message
      data_template:
        message: "{{ state_attr('sensor.next_birthday', 'name') }} is {{ state_attr('sensor.next_birthday', 'age') }} geworden vandaag!"
        disable_notification: false

Also getting an error for this automation:
Conditions: expected str for dictionary value @ data[0]['state']

Yeah this has been on my todo a long time, at the moment it only returns one name. I will try to get something working soon, at the moment it is sadly only 1 person that is provided by sensor.next_birthday. Regarding Conditions: expected str for dictionary value @ data[0]['state'], it could be that it is expecting state: "0". Will test and update together with the other things

@htodep Automation documentation is now updated with improved sensor where you get all birthdays in one push! Let me know if something is missing or not working ๐ŸŽ‰

@Miicroo That was fast! Thank you so much. Have implemented the new template sensor and updated the automation.
Getting errors but I think its because there are no birthdays:

Send notification for birthday: Error executing script. Invalid data for call_service at pos 1: template value is None for dictionary value @ data['message']

Error while executing automation automation.send_notification_for_birthday: template value is None for dictionary value @ data['message']

@htodep Ahhh, I think I found it! It seems that the notify.telegram_-service somehow doesn't support templates(?). I don't use telegram so I can't test it out properly, but here is a HomeAssistant forum thread where they solve the problem by using the telegram_bot integration for sending push notifications instead. Or maybe it can work if you just replace data_template with data?

@Miicroo I'm not really technical but it doesn't find the sensor anymore "sensor.next_birthday" with the new sensor template.
I'm using this in my configuration.yaml:
sensor: !include_dir_merge_list includes/sensors/

And this in my /includes/sensors/birthdays.yaml

template:
  - sensor:
    - name: "Next birthday"
      state: >

This is my automation:

- id: birthday_reminder
  alias: Send notification for birthday
  trigger:
    platform: time
    at: '08:00:00'
  condition:
    condition: state
    entity_id: sensor.next_birthday
    state: '0'
  action:
    - service: telegram_bot.send_message
      data:
        message: '{{ state_attr(''sensor.next_birthday'', ''birthday_message'') }}'
        disable_notification: false

@htodep It could be a missing unique_id on my end in the documentation, if HA has an old template with unique_id set and the new one doesn't, it will add a _2 at the end. If you update the template so the name part looks like this:

  - name: "Next birthday"
    unique_id: "next_birthday"

Does that bring back the sensor.next_birthday?

@Miicroo Nope. can't find the entity, if i search voor "next" or "birthday" nothing comes up except the list of birthdays

@htodep Reread your latest message and realize what is missing, the new style of templates has their own configuration! (Not stored in sensors folder) You should move the next_birthday sensor to a new yaml file in includes/templates and add this to your HA configuration.yaml

tenplate: !include_dir_merge_list includes/templates/

@Miicroo You are right! Missed a couple of changes haha.
I added a helper template via the UI and it gives me the current birthdays, so that's a step in the right direction.
Now I want to send a message with the state_attr you provided but I cant get it to work! So frustrating. I'm not sending the message with telegram anymore but with the notify service of the companion app. But still, not working. Maybe you know what wrong with it? Or how I should do this?

This is my automation:

- id: birthday_reminder
  alias: Send notification for birthday
  trigger:
    platform: time
    at: '08:00:00'
  condition:
    condition: state
    entity_id: sensor.next_birthday
    state: '0'
  action:
    - service: notify.all_phones
      data_template:
        title: Hieperdepiep
        message: "{{ (state_attr('sensor.next_birthday', 'birthday_message')) }}"

This has nothing to do with your integration but with my incompetence...

@Miicroo I was so frustrated! Couldn't handle it. I removed the helper and did the include in my config:
template: !include_dir_merge_list includes/templates/

Then put the template script back in the /templates/birthday.yaml file and adjusted my automation to:

- id: birthday_reminder
  alias: Send notification for birthday
  trigger:
    platform: time
    at: '08:00:00'
  condition:
    condition: state
    entity_id: sensor.next_birthday
    state: '0'
  action:
    - service: telegram_bot.send_message
      data_template:
        message: "{{ state_attr('sensor.next_birthday', 'birthday_message') }}"

And it worked like charm...
Thank you for helping me out, much appreciated

@htodep Wow, nice work! Happy to help and glad that it worked out, nice that I was finally able to update some of the documentation in this repo too! ๐Ÿ˜ƒ