Notification and automation not work

Hi everyone,
I have a package with:

group:
  zigbee_sensors:
    name: Zigbee Sensors Battery Group
    entities:
      - sensor.aqara_temp_studio_battery
      - sensor.pir_bagno_battery
      - sensor.pir_disimpegno_battery

automation:
  - alias: Notifica batteria bassa Zigbee
    trigger:
      platform: numeric_state
      entity_id: group.zigbee_sensors
      value_template: "{{ state.attributes.battery }}"
      below: 90
    action:
      - service: notify.mobile_app_le2123
        data:
          title: ' Batteria sensori'
          message: "La batteria del sensore {{ trigger.to_state.name }} è bassa ({{ trigger.to_state.attributes.battery }}%)!"
    mode: single

I would like to receive notifications when one of the sensors on the group drops below 20%. What am I doing wrong?

I don’t want use blueprint

Thank you

You’re using an old-style group which the documentation doesn’t show it supports grouping sensors.

Even if you use the new-style group (which does support sensors) you have to specify how you want to group the sensor values (see: Sensor Groups). For example, if you choose to show the average, it won’t be useful for your intended application (report when one of the sensors falls below 20%).

In addition, your Numeric State Trigger uses a value_template to get the value from the sensor’s battery attribute. Does each one of the three sensors report battery level in an attribute named battery or in its state property?

I suggest you forego using a group and simply list the entities directly in the Numeric State Trigger. Alternately, use a Template Trigger that monitors all sensors whose entity_id ends with the word “_battery”. Either way, it’s important that you confirm where each sensor stores the battery level (in its state or in attributes).

Or use an existing blueprint. Here’s one designed to monitor battery level.

Hi,

thank you.

i have removed group

automation:
  - alias: Notifica batteria bassa sensori zigbee
    trigger:
      platform: numeric_state
      entity_id:
        - sensor.aqara_temp_studio_battery
        - sensor.pir_bagno_battery
        - sensor.pir_disimpegno_battery
      below: 20
    action:
      - service: notify.mobile_app_le2123
        data_template:
          title: "Batteria Bassa"
          message: "Il livello della batteria è al di sotto del 20% per il sensore {{ trigger.to_state.attributes.friendly_name }}."

-14 14:17:26.258 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'to_state' when rendering 'Il livello della batteria è al di sotto del 20% per il sensore {{ trigger.to_state.attributes.friendly_name }}.'
2024-01-14 14:17:26.258 ERROR (MainThread) [homeassistant.components.automation.notifica_batteria_bassa_sensori_zigbee] Notifica batteria bassa sensori zigbee: Error executing script. Error for call_service at pos 1: Error rendering data template: UndefinedError: 'dict object' has no attribute 'to_state'
2024-01-14 14:17:26.260 ERROR (MainThread) [homeassistant.components.automation.notifica_batteria_bassa_sensori_zigbee] Error while executing automation automation.notifica_batteria_bassa_sensori_zigbee: Error rendering data template: UndefinedError: 'dict object' has no attribute 'to_state'

Can you show me a example? please…

Thank you

How did you test the automation? If you used the automation’s Run command then it explains why it produced an error.

The Run command only executes the automation’s actions, it skips the automation’s trigger and condition.

By skipping the automation’s trigger, the trigger variable was never created so trigger.to_state.attributes.friendly_name doesn’t work.

Reference

Testing your automation


Here’s a way to trigger the automation’s Numeric State Trigger without waiting for one of the three sensors to decrease below 20.

You can temporarily “force” the sensor’s value to be less than 20.

  1. Go to Developer Tools > States
  2. Find sensor.pir_bagno_battery in the list and click it.
  3. Scroll to the top of the page where all of the sensor’s properties are displayed in a form.
  4. Take note of its current State value (perhaps make a copy of it). It should currently be above 20 in order for the test to work.
  5. Change the value to 19 or anything less than 20.
  6. Click the Set State button.
  7. That should be sufficient to trigger the automation’s Numeric State Trigger.

Optionally, use the same technique to set the sensor’s value back to the original temperature. Otherwise, simply wait for the sensor’s integration to update the sensor’s value.

Thank you.

It work

1 Like