Alert, how is this working?

I’m just a beginner and want to have an Alert when a lamp is on for some minutes, I did check all kind of constructions and the current one is generating Alerts every second or so… For sure I do something wrong but can’t figure out the problem. HA version is 87.0

I hope someone can give me some directions,

many thanks in advance,

Peter

binary_sensor:
    platform: template
    scan_interval: 5                # seconds
    sensors:
      lmp:
        value_template: "{{is_state('light.hue_go_2','on') }}"



alert:
 light_hue:
        name: Hue lamp on                 # ALARM message string
        done_message: hue lamp off        # end ALARM messsage string
        entity_id:  binary_sensor.lmp     # binary sensor
        state: 'on'                       # problem condition
        repeat: 2                         # each 2 minutes notify
        can_acknowledge: true
        skip_first: true                  # send notification after first delay
        notifiers:
          - ios_iphone_peter

Please format your code using the </> button in the editor.

image

I never used the alert function, but first I would do is remove the scan_interval from your binary sensor as it will update on state change anyway.

How did you install Home Assistant? If you’re not using Hass.io/Docker, is the timezone set in Home Assistant the same as the timezone set in the OS?

I ran into a problem way back, and again more recently (6 ish months back) when checking where if the timezones were different alerts would be fired out at around one a second or so.

maybe not relevant in your setup, but you are using a hue light for triggering this alert. Hue is very ‘dangerous’ (read unreliable) for this use case, since the HA Hue integration looses connection to the lights ever so often. See: All my hue lights randomly becoming unavailable among many others threads on this topic.

Having that for a trigger isn’t the best way to test you alerts…I was forced to stop using Hue light states for triggers in regular automations just because of that. Seeing you are using a binary_sensor to top that, makes it even more precarious, since binary_sensors have been an issue in the Hue integration also. Might be solved meanwhile, but I’ve taken out as many as I could just to be sure.

My advice in testing alerts would be not to use hue light states… especially not the hue_go, which has connection irregularities of its own :wink:

Ive used this in my setup to see what was going on and I was amazed about the activity (that wasn’t there of course, simply indicating HA lost Hue lights)

- alias: 'State changed Light'
  id: 'State changed Light'
  initial_state: 'off'
  trigger:
    platform: event
    event_type: state_changed
  condition:
    condition: template
    value_template: >
      {{ trigger.event.data.entity_id in state_attr('group.all_lights_only','entity_id') }}
  action:
    service: notify.notify
    data_template:
      message: >
       {{trigger.to_state.attributes.friendly_name}} changed from {{trigger.from_state.state}} to {{trigger.to_state.state}}

this is my working alert config

  water:
    name: Water Kitchen
    message: "Water has been detected in the kichten for {{ relative_time(states.binary_sensor.water_keuken.last_changed) }}"
    done_message: "Water issue has been taken care"
    entity_id: binary_sensor.water_keuken
    state: 'on'
    repeat:
      - 10
      - 15
      - 30
      - 60
    can_acknowledge: true
    skip_first: true
    notifiers:
      - android

Thanks to all of you, I did use your advices and improved my code, the solution however was the timezone.

After making the timezone in the Raspberry the same as in the configuration.yaml the alert was working as expected.

Have a nice week-end and thanks again !

Thanks for confirming that. I’ve opened an issue so the devs can hopefully look into it.