[Solved] Could someone help me to understand automation with event as trigger?

Hi guys. I tried to automate some stuff reading documentation here: https://www.home-assistant.io/docs/configuration/events/ and here: https://www.home-assistant.io/docs/automation/trigger/

Actually, plan was some different automation, dim lights on Kodi playing and raise back on Kodi paused/idle, but since this not worked, I’m trying to make basic simple case and understand how things are going with events. Unfortunately, below is not working as well. Want to get HA android app notification when light bulb is turned on and another HA android app notification when light bulb is turned off. Below is my setup.

Configured from GUI:

was produced following in automations.yaml

- id: '1584706054922'
  alias: test bulb on
  description: ''
  trigger:
  - event_data:
      entity_id: light.bulb
      new_state: 'on'
      old_state: 'off'
    event_type: state_changed
    platform: event
  condition: []
  action:
  - data:
      message: sijalica je upaljena
    service: notify.mobile_app_sagit
- id: '1584706254500'
  alias: test bulb off
  description: ''
  trigger:
  - event_data:
      entity_id: light.bulb
      new_state: 'off'
      old_state: 'on'
    event_type: state_changed
    platform: event
  condition: []
  action:
  - data:
      message: sijalica je ugasena
    service: notify.mobile_app_sagit

When I toggle on/off this particular bulb, nothing happens, notifications are not arriving. I would mention also that same notifications are working for me, I’m using it when game is started on Playstation, but here I’m using state which is bit more simple for me. I never before used event.

I would also mention that bulb was toggled on/off from HA.

Unfortunately, there is nothing related in logs, either in Frontend Logbook or in /home-assistant.log , so I assume that my syntax isn’t good.

Could someone help me, thanks.

No need to use an event trigger here. A state trigger would work fine. Same with the Kodi automation you were trying to make.

- id: '1584706054922'
  alias: test bulb on
  trigger:
    platform: state
    entity_id: light.bulb
    from: 'off'
    to: 'on'
  action:
    service: notify.mobile_app_sagit
    message: sijalica je upaljena
    

- id: '1584706254500'
  alias: test bulb off
  trigger:
    platform: state
    entity_id: light.bulb
    from: 'on'
    to: 'off'
  action:
    service: notify.mobile_app_sagit
    message: sijalica je ugasena

Or using just one automation:

  alias: test bulb on or off
  trigger:
    platform: state
    entity_id: light.bulb
  action:
    service: notify.mobile_app_sagit
    data_template:
      message: >
        {% if trigger.to_state == 'on' %}
          sijalica je upaljena
        {% elif trigger.to_state == 'off' %}
          sijalica je ugasena
        {% else %}
          sijalica nije definirana
        {% endif %}

Thanks a lot guys, it seems I didn’t understood “State” automation trigger process before at all.

image

I was meant that “From” and “To” fields are supposed for time and always left it blank. Then I was used “ADD CONDITION” button below and was adding Condition type: “State” again, with same entity as above and state mostly on or off (playing or paused, etc.). This way, some automation were gives me double, triple notifications and/or bulb continue to turning on, no matter if I turn it off. This is normal in this case and I was meant that HA is buggy :slight_smile:

Now I understand that From is old_state and To is the new_state, thanks once again.

From my point of view, both answers above are “Solution”. I guess I can mark only one, so will not mark any :slight_smile: , sorry.

Give it to Tedi. He needs needs them like food. :rofl:

done :joy: :sweat_smile: :rofl: :joy:

Can you spare a solution checkmark in these trying times? :stuck_out_tongue:

No but I have plenty of :roll_of_toilet_paper:

1 Like

Depends … Are you showing any symptoms… ?
Can you please stand in line with 2,000 other people in close proximity for 6 hours so we can take your temperature ?

It would be be funny, if it weren’t true.