#Notification when update available?

1 messages · Page 1 of 1 (latest)

lunar matrix
#

Hi all. Looking to try and set up mobile notifications when there are updates for most things. HAOS, Home Assistant, and HACS. Might be more that I'm not thinking of? What do ya'll do for this? I've seen a few templates and automations on the forum but many are older and have replied that they no longer work.

mossy marlin
prime solstice
#
triggers:
  - trigger: template
    value_template: |-
      {{ states.update
        | selectattr('state', 'eq', 'on') 
        | map(attribute='entity_id')
        | list
        | count > 0}}

lunar matrix
#

So I'll use that as a template trigger and then that should trigger when any entity with update changes to on? Or do I still need the group with all the devices in it? Sorry still trying to come up to speed on all this.

In addition can I use the following in the notification so it tells me which entity has the update? I have this working for when a water sensor detects water it tells me which one it was.

{{ trigger.to_state.name }} has an update.

#

Also I just saw that you could have the action automatically install the update. But that seems.... bold? and scary. Having it notify and manually doing it seems like the right play? Is that what ya'll do?

prime solstice
#

This is my full automation:

alias: Notify user about device updates
description: >-
  Send a notification when devices have updates available, ensuring prompt
  action to keep all systems current.
triggers:
  - trigger: template
    value_template: |-
      {{ states.update
        | selectattr('state', 'eq', 'on') 
        | map(attribute='entity_id')
        | list
        | count > 0 }}
conditions: []
actions:
  - action: notify.<my_phone_goes_here>
    metadata: {}
    data:
      title: New update available
      message: >-
        At least one device is available for an update. Please check inside Home
        Assistant
mode: single

#

I don't care about which update, I just care about one. I do not receive the name of device, just number of devices. And basically, trigger will fire when number of update. entities with update state active goes from 0 to 1. Transition trigger.

#

In fact, because when I built the template trigger, I used the template editor, but you can remove the map part, and do this:

{{ states.update
  | selectattr('state', 'eq', 'on') 
  | list
  | count > 0 }}

Automation will fire when state goes from false to true

#

I have automatic update for my zigbee devices connected with Z2M, mostly lights. but my "auto" is manually triggered, however when it is, it will update all the devices in a sequence, one by one. Otherwise zigbee network is too occupied and sometimes updates fail

lunar matrix
#

Ah got ya ok. I set mine up like this. In theory should work?

Dumb question but I used the GUI builder. Why does my value_template have |2?

description: ""
triggers:
  - trigger: template
    value_template: |2-
            {{ states.update
              | selectattr('state', 'eq', 'on') 
              | list
              | count > 0}}
conditions: []
actions:
  - action: notify.mobile_app_kyle_phone
    metadata: {}
    data:
      message: "{{ trigger.to_state.name }} has an update."
mode: single
prime solstice
#

the trigger.to_state.name I don't think exists. Why, because the trigger state moves from "false" to "true". If you check the template, it is a logical expression, saying "when number of update entities in state = on is greater than 0", and not which one.

#

if you want to print the name of all or first entry, then what you'd need to do is the following

#
{{ states.update
  | selectattr('state', 'eq', 'on')
  | map(attribute='attributes.friendly_name')
  | list
  | join(', ')}}
#

This will print all the friendly names of the entities where the update is active

#

So your automation would look like:

alias: Update Available
description: ""
triggers:
  - trigger: template
    value_template: |2-
            {{ states.update
              | selectattr('state', 'eq', 'on') 
              | list
              | count > 0}}
conditions: []
actions:
  - action: notify.mobile_app_kyle_phone
    metadata: {}
    data:
      message: "Updates: {{ states.update | selectattr('state', 'eq', 'on') | map(attribute='attributes.friendly_name') | list | join(', ') }}."
mode: single
#

I faked the update availability in developer tools -> states and got the following message to my phone

lunar matrix
#

Ahhh got ya. The water one works because the sensor is the one that triggers it. Right?

Ohhh awesome! Thanks!

prime solstice
#

Water?

lunar matrix
#

I have a water sensor automation but it triggers based on the entity itself. Which I think is why that notification for trigger.to_state.name works? Here it is.

description: ""
triggers:
  - trigger: state
    entity_id:
      - binary_sensor.bathroom_sink_water_sensor_water_leak_detected
    from:
      - "off"
    to:
      - "on"
  - trigger: state
    entity_id:
      - binary_sensor.bathroom_water_sensor_water_leak_detected
    from:
      - "off"
    to:
      - "on"
  - trigger: state
    entity_id:
      - binary_sensor.dishwasher_water_sensor_water_leak_detected
    from:
      - "off"
    to:
      - "on"
  - trigger: state
    entity_id:
      - binary_sensor.fridge_water_sensor_water_leak_detected
    from:
      - "off"
    to:
      - "on"
  - trigger: state
    entity_id:
      - binary_sensor.kitchen_sink_water_sensor_water_leak_detected
    from:
      - "off"
    to:
      - "on"
  - trigger: state
    entity_id:
      - binary_sensor.laundry_room_water_sensor_water_leak_detected
    from:
      - "off"
    to:
      - "on"
  - trigger: state
    entity_id:
      - binary_sensor.master_bath_sink_water_sensor_water_leak_detected
    from:
      - "off"
    to:
      - "on"
  - trigger: state
    entity_id:
      - binary_sensor.master_bath_water_sensor_water_leak_detected
    from:
      - "off"
    to:
      - "on"
  - trigger: state
    entity_id:
      - binary_sensor.water_heater_water_sensor_water_leak_detected
    from:
      - "off"
    to:
      - "on"
conditions: []
actions:
  - type: turn_off
    device_id: 4dfbe26c75834cb5863b16eca590064f
    entity_id: 1ac411121eafdf63c779c3d9c3720545
    domain: switch
  - action: notify.mobile_app_kailynn_phone
    metadata: {}
    data:
      message: "{{ trigger.to_state.name }} has detected a leak."
  - action: notify.mobile_app_kyle_phone
    metadata: {}
    data:
      message: "{{ trigger.to_state.name }} has detected a leak."
mode: single
prime solstice
#

yes because here you are acting on specific entity

#

in my example, you don't care "which entity", you trigger on "number of entities in certain state is above 0"

#
    device_id: 4dfbe26c75834cb5863b16eca590064f
    entity_id: 1ac411121eafdf63c779c3d9c3720545

this is bad, btw!

lunar matrix
#

Ok cool. Starting to understand a bit more. 😛 I'll get there eventaully. Explains why I couldn't make a group of the water sensors and still have it tell me who triggered. As then the group triggers it not the specific entity.

Idk why that's in there like that? I added it like the others I thought... I haven't been looking at YAML to be honest. Moslty GUI edits.

#

I should point to the entity not the device. Right?

prime solstice
#

If you have a group of the entities of your leak sensors

#

you could do the trigger when group becomes "on" from "off". Group has to be configured in or configuration, so that at least one sensor in "on" means full group is on.

lunar matrix
#

Ya I had that all set like that. But when I did. The alert only showed the group. Not the specific one who triggered it.

prime solstice
#

yes, because you would need to extract the group entities and show the list of entities that are currently "on"

#

let me find an exmaple for you

#

so in my case I have a group for presence. There are 2 binary sensors. I have my trigger on a group

#
{{ 'binary_sensor.office_presence_occupancy'
    | expand
    | selectattr('state', 'eq', 'on')
    | map(attribute='attributes.friendly_name')
    | list
    | join(', ') }}
#

When both sensors detect me, I get: Presence sensor office Presence Sensor 1, Hue Motion Sensor 1 - office Occupancy

#

and when motion stops detecting while mmwave sensor continues, I get: Presence sensor office Presence Sensor 1

lunar matrix
#

Ah ok so that unpacks the group in a similar way to how you did the updates.

Would this be a better way to do the valve? It's bad to directly reference a device as you can't easily replace it with another right? But it does technically work. Ya?

    metadata: {}
    data: {}
    target:
      entity_id: switch.water_valve```