Chouffy/home_assistant_tgtg

Notification Template

Closed this issue · 3 comments

Hi, first of all thanks for the Integration. This is not really a Issue but unfortunately there is no discussion part in this github.
I made this automation to notify me whenever a store I like has new items. I am just curious if you have a better way of doing it instead of listing all entity_id's. If not I just wanted to share because I would have liked a template :).

alias: tgtg notify
trigger:
  - platform: state
    entity_id:
      - sensor.long
      - sensor.list
      - sensor.of
      - sensor.all
      - sensor.tgtg
      - sensor.stores
action:

#send notification if stock changes from 0 or unavailable to >=1
  - choose:
      - conditions:
          - condition: template
            value_template: '{{ trigger.to_state.state | float >= 1 }}'
          - condition: template
            value_template: >-
              {{ trigger.from_state.state | float == 0 or
              trigger.from_state.state == "unavailable" }}
        sequence:
            #change notification method
          - service: notify.mobile_app_iphone
            data_template:
              message: '''{{ trigger.from_state.attributes.friendly_name }}'''
              #you don't need the tag if you don't use a Iphone and want to delete messages
              data:
                tag: '''{{ trigger.from_state.attributes.friendly_name }}'''
    default: []

#this is only possible with Iphone I think
#delete notification if stock changes back to 0
  - choose: 
      - conditions:
          - condition: template
            value_template: '{{ trigger.to_state.state | float == 0 }}'
        sequence:
          - service: notify.mobile_app_iphone
            data:
              message: clear_notification
              data:
                tag: '''{{ trigger.from_state.attributes.friendly_name }}'''
    default: []
mode: parallel
max: 10

Hey @wieluk,

I just activated the Discussion tab so we can move here if you want!
Also thanks for this template example: in my case I used the visual Script editor to do it but it's nice to have a different example.

Regarding listing all entity_id : I don't know other way than doing this 😥
In another custom Table card for Lovelace you can define wildcards like include: sensor.tgtg* ... but I'm pretty sure this doesn't work on our case

Would be great if you can recreate this thread in Discussion, so I can close the issue!
Also I've edited your code to add styling (```yaml at the beginning)

Thanks, I added it to discussions