Alerts don't seem to work

Hello everyone.

I am trying to setup alerts to let me know when my sensor’s battery is below a certain value.

My configuration.yaml:

notify ios:
  - name: iOS
    platform: group
    services:
      - service: ios_iphone7
      - service: ios_ipadair2

sensor:
  - platform: template
    sensors:
      bedroom_sensor_battery_low:
        value_template: '{{ states.sensor.temperature_158d0001571539.attributes.battery_level < 50 }}'
        friendly_name: 'Bedroom sensor battery is low'

alert: bedroom_sensor_battery_low:
  name: Bedroom sensor battery is low
  entity_id: sensor.bedroom_sensor_battery_low
  state: 'on'
  repeat: 3600
  skip_first: False
  notifiers:
    - notify.ios

In Developer Tools, entity shows the following:

Entity: sensor.temperature_158d0001571539	
State: 25.04	
Attributes:
battery_level: 39
friendly_name: Temperatura
homebridge_name: Temperatura Quarto
unit_of_measurement: °C
icon: mdi:thermometer

and also:

Entity: sensor.bedroom_sensor_battery_low	
State: True

and last but not least:

Entity: alert.bedroom_sensor_battery_low
State: idle

In the log, I can also see the following on restart:

DEBUG (MainThread) [homeassistant.components.alert] Watched entity (sensor.bedroom_sensor_battery_low) has changed

Still then, no notification is ever sent to me, even if the battery level value has changed during the course of the day (with values below the threshold of 50):

Am I missing something on the way the alerts are supposed to be working or do you see anything wrong in my config?

Thanks in advance for any help.

You ALERT when the sensor state is “on” but your tools tell you that the sensor state is “True”
I would say that “on” is not the same as “True”
Try changing your alarm to state: ‘True’

1 Like

The sensor started as a binary_sensor and ended up as a sensor exactly because it could only be on/off. That’s why it said ‘on’. Changing it to ‘True’ seems to have the done the trick.

At least now I can see 2 lines like these in the log:
DEBUG (MainThread) [homeassistant.components.alert] Beginning Alert: Bedroom sensor battery is low INFO (MainThread) [homeassistant.components.alert] Alerting: Bedroom sensor battery is low

I didn’t get the actual notification but I suppose this is because of a line which appears later in the log:
INFO (MainThread) [homeassistant.components.notify] Setting up notify.ios

I’ll leave it running, to see if the notification appears after the 3600 seconds I defined to receive the alert again.

Thanks a lot.

Unfortunately, although I defined 3600 seconds to get daily notifies, I get none.

These lines also don’t seem to appear anymore in the log:
DEBUG (MainThread) [homeassistant.components.alert] Beginning Alert: Bedroom sensor battery is low INFO (MainThread) [homeassistant.components.alert] Alerting: Bedroom sensor battery is low

Any ideas?

Would this be better setup as an automation?

The problem I see in this instance with alert is if the battery trips the alert at 0100 then every day at 0100 you get the alert.

With an automation you could trigger everyday at 1800 with a condition of the battery being low.

Just a thought.

That might actually be an option, I actually stumbled upon the alert component and was trying to get it done this way.

Still then, an automation might be hit & miss, depending on how often you’d trigger the action.

Anyone else could get the alert component to work properly in a scenario like this?

I think the simple mistake is that you should only put the notifier name in the end statement and not notify.NAME (at least that is how I did in my setup and it works great)

alert: bedroom_sensor_battery_low:
  name: Bedroom sensor battery is low
  entity_id: sensor.bedroom_sensor_battery_low
  state: 'on'
  repeat: 3600
  skip_first: False
  notifiers:
    - ios

Also, I think the repeat parameter is in minutes. So 3600 means every 60 hours

What you are trying to do is precisely in the docs, you should check it in detail.

I had noticed both my mistakes before reading your post, but my working config was almost as you mentioned:

  • State needs to be ‘True’ because I’m using a template sensor rather than a binary sensor;

  • I thought the repeat was in seconds, but it actually seems to be in minutes.

    bedroom_sensor_battery_low:
    name: Bedroom sensor battery is low
    entity_id: sensor.bedroom_sensor_battery_low
    state: ‘True’
    repeat: 1440
    skip_first: False
    notifiers:
    - ios

Thanks a lot for all your help.

1 Like