Notification for overtemperature and overpower for all Shelly devices

Hi,

I would like to have a notification if any of my shelly devices gets an over temperature and/or over power warning, what is the best way to do that? Having to write an automation for each individual device is a bit annoying since I have 39 already and plan to add quite a few more.

1 Like

You can write a template trigger. To help you with this we would need to know some of the entity ids and the state(s) you want to match.

1 Like

2 posts were split to a new topic: Https://community.home-assistant.io/t/shelly4hass-current-consumption-state-w-cannot-be-processed-as-a-number/453352/5

Great, I made a mess and replied to the other thread in this one.

{{ states(‘binary_sensor.shelly_shplg_s_ddde55_over_power’) }}
Result type: string

off

{{ states(‘binary_sensor.shelly_shplg_s_ddde55_over_temp’) }}
Result type: string

off

This will trigger if any binary sensor with “over_power” or “over_temp” in the entity_id turns on.

trigger: 
  platform: template
  value_template: >
    {{ states.binary_sensor
       |selectattr("entity_id", "search", "(_over_power|_over_temp)")
       |selectattr('state','eq', 'on')
       |list|count > 0 }}

It has an issue that my be important to you. It will not trigger again until none of these sensors are on and one (or more) then turns on. So for example if you already have one over_temp or over_power on and another turns on, it will not trigger this second (or subsequent) time(s). I’m still trying to think of a way around this. You might have to make a template sensor and use a state trigger with no above or below option and a template condition that checks if the trigger_to state is greater than the trigger_from state. Like this:

configuration.yaml:

template:
  - sensor:
      - name: Number of Over Temp or Over Power Alarms
        state: >
          {{ states.binary_sensor
             |selectattr("entity_id", "search", "(_over_power|_over_temp)")
             |selectattr('state','eq', 'on')
             |list|count }}

You would then use it in an automation like this:

trigger:
  platform: state
  entity_id: sensor.number_of_over_temp_or_over_power_alarms
  to:
condition:
  - "{{ trigger.from_state.state not in ['unknown', 'unavailable'] }}"
  - "{{ trigger.to_state.state not in ['unknown', 'unavailable'] }}"
  - "{{ trigger.to_state.state |int > trigger_from_state.state |int }}"
action:
 - service: notify.notify
   data:
     message: >
      Over Temp/Power detected from 
          {{ states.binary_sensor
             |selectattr("entity_id", "search", "(_over_power|_over_temp)")
             |selectattr('state','eq', 'on')
             |list|join(', ' }}

There might be a way to do this just with the trigger. I’m still thinking about it and will post a reply if I think of anything.

1 Like

thanks @tom_l for providing this, trying to add it into an automation it gives me:

Message malformed: template value should be a string for dictionary value @ data[‘action’][0][‘data’]

any ideas?

Last line missing a bracket.

|list|join(', ') }}
1 Like

@tom_l was looking for exactly this automation, and currently have this:

alias: Shelly Over Power or Over Heating Alert
description: ""
trigger:
  - platform: state
    entity_id:
      - sensor.shelly_over_power_or_over_heating_alarms
condition:
  - "{{ trigger.from_state.state not in ['unknown', 'unavailable'] }}"
  - "{{ trigger.to_state.state not in ['unknown', 'unavailable'] }}"
  - "{{ trigger.to_state.state |int > trigger_from_state.state |int }}"
action:
  - service: persistent_notification.create
    data:
      message: |
        Over Power/Heat detected from 
            {{ states.binary_sensor
               |selectattr("entity_id", "search", "(_overpowering|_overheating)")
               |selectattr('state','eq', 'on')
               |list|join(', ') }}
mode: single

A couple of things if anyone can assist?

This does not seem to action with the conditions (removing the conditions works, but I get a notification when the number goes from 1 back to 0.

Also, how do I just use “friendly_name” in the notification, as at the moment it gives me this:

Over Power/Heat detected from
<template TemplateState(<state binary_sensor.shelly1pm_8caab5775a46_overpowering=on; device_class=problem, friendly_name=Coffee Machine Overpowering @ 2023-07-27T10:06:04.127171+12:00>)>

Typo in the third condition: trigger.from_state.state not trigger_from_state.state. This is why it’s important to understand and re-type rather than simply copy & paste — the error was in Tom’s original above, but the code that we suggest is hand-typed and often untested, as our systems’ config doesn’t match yours.

In the message, add |map(attribute='friendly_name') before the |list.