davesmeghead / visonic

Visonic Custom Component for integration with Home Assistant
Apache License 2.0
91 stars 20 forks source link

Home Assistant new events do not appear after the migration? #147

Closed Joao-Sousa-71 closed 1 month ago

Joao-Sousa-71 commented 2 months ago

Dave,

I have the integration working with the beta version 0.9.7.7 and the HA template sensors adapted to the new attributes and now it is time to adapt the automations and I've notice something really odd. These are my setting within the new configuration:

image

When looking to Developper Tools -> Events I see this:

image

But according to the Wiki the events have now different names:

image

Is this because of the upgrade? Should I remove complete the integration and add it again?

Next, I have a full hand of automations based on events like this:

- id: notify_alarm_siren_triggered_action_ios
  alias: notify_alarm_siren_triggered_action_ios
  description: 'Notifica Casa Alarmada - Sirene Ativa'
  initial_state: true
  trigger:
    platform: event
    event_type: visonic_alarm_panel_state_update
    event_data:
      condition: 3
  condition:   
    - condition: template
      value_template: >
        {{ (trigger.event.data['Entity']|string) != 'None' }}              
  variables:
    event_title: >
      {% if trigger.event.data['Mode'][0] == 'Perimeter Alarm' or trigger.event.data['Mode'][0] == 'Delay Alarm' or trigger.event.data['Mode'][0] == 'Confirm Alarm' %}
        Alarme INTRUSAO Z{{ trigger.event.data['Zone'] | string }} {{"\U0001f6a8\U0001f6a8\U0001f6a8"}}
      {% elif trigger.event.data['Mode'][0] == 'Fire' %}   
        Alarme FOGO Z{{ trigger.event.data['Zone'] | string }} {{"\U0001f525\U0001f525\U0001f525"}}
      {% elif trigger.event.data['Mode'][0] == 'Flood Alert' %}
        Alarme INUNDACAO Z{{ trigger.event.data['Zone'] | string }} {{"\U0001f4a7\U0001f4a7\U0001f4a7"}}
      {% else %}
        Alarme Outros {{ trigger.event.data['Mode'][0] | string }} {{"\u2753"}}
      {% endif %}        
    alarm_subtitle: >
      {% set ety = trigger.event.data['Entity']|string %}
      {% if ety == 'None' %} 
        {{ "" }}
      {% else %}
        Zona  - {{ state_attr(ety, 'friendly_name') }} Alarmada
      {% endif %}      
  action:
....

In the new Wiki I don't find the conditions like "3", "1" etc as before . What I'm missing? How this is suppose to work now? Sorry for these questions and I feel somehow lost but this migration it is not being straight but I trust we will get there :-) Thank you, João

PS: I have updated the #131

davesmeghead commented 2 months ago

Is this because of the upgrade?

Yes. I did say that this release was a breaking change, especially for automations

Should I remove complete the integration and add it again?

No

A lot of the old event values are now in the entities (some were anyway) Using your example automation, you trigger on an event with condition 3. This meant "siren sounding".
You now look at the Alarm Panel Entity when it is in the Triggered state (also the attribute siren is set to true). So maybe like this (untested as an example)

trigger:
  - platform: state
    entity_id:
      - alarm_control_panel.visonic_alarm
    from: armed_away
    to: triggered

For things like the following i.e. what used to be event data trigger.event.data['Mode'][0] == 'Perimeter Alarm' trigger.event.data['Zone']

is now available in the Alarm Panel Entity as

lasteventname: System
lasteventaction: Installer Programming
lasteventtime: 28/08/2024, 07:25:38

Please do not use the lastevent attribute, the above provides the same information without the "/"

Best Regards Dave

Joao-Sousa-71 commented 2 months ago

ok, if I understood the new logic then an automation like this:

- id: notify_visonic_event_triggered_action_ios
  alias: notify_visonic_event_triggered_action_ios
  description: 'Notifica Alarme - Evento Detectado'
  initial_state: true
  trigger:
    platform: event
    event_type: visonic_alarm_panel_state_update
    event_data:
      condition: 1
  condition:
    - condition: template
      value_template: > 
        {{ trigger.event.data['Event'] != 0 and trigger.event.data['Event'] != 3 and trigger.event.data['Event'] != 4 and trigger.event.data['Event'] != 5 }}
  variables:
    event_title: >
      {% if trigger.event.data['Event'] == 6 %}
        Alarme PANICO {{"\U0001f4a5"}}
      {% elif trigger.event.data['Event'] == 9 %}
        Alarme FALHA COM {{"\U0001f4f5"}}
      {% elif trigger.event.data['Event'] == 10 %}
        Alarme FALHA LINHA {{"\u260e\ufe0f"}}            
      {% elif trigger.event.data['Event'] == 1 or trigger.event.data['Event'] == 17  %}  
        Alarme TAMPER {{"\u26a0\ufe0f"}}
      {% elif trigger.event.data['Event'] == 2 or trigger.event.data['Event'] == 18  %}  
        Alarme TAMPER RESTORE {{"\u2714\ufe0f"}}        
      {% elif trigger.event.data['Event'] == 13 or trigger.event.data['Event'] == 19  %}  
        Alarme BATERIA FRACA {{"\U0001f50b"}}
      {% elif trigger.event.data['Event'] == 14 or trigger.event.data['Event'] == 20  %}  
        Alarme FALHA AC {{"\U0001f50c"}}        
      {% else %}
        Alarme OUTROS #{{ trigger.event.data['Event'] | string }} {{"\u2753"}}
      {% endif %}
    event_subtitle: >
      {% set evt = trigger.event.data['Event'] | string %}
      {% if evt == null %} 
        Evento nao identificado
      {% else %}
        Evento:{{ evt }} - {{ trigger.event.data['Description'] }} 
      {% endif %}    
    event_message: >
      Detetado as {{ now().strftime('%T - %d/%m/%Y') }}
  action:
...

Should rely in the new version on the attribute "trouble" and what was:

trigger.event.data['Event'] == 14 or trigger.event.data['Event'] == 20

is now:

 state_attr('alarm_control_panel.visonic_alarm', 'trouble') == 'Battery'

Oh man, I think I need a knife to slit my wrists... just kidding :-)

Thanks again, João

davesmeghead commented 2 months ago

Hi, Yes that looks correct. I've just released "0.9.7.9 - English Translation File, Logic Updates and Bug Fixes" to dev_B0, if you get the chance please give it a try. If you look in the en.json file in the languages directory it provides all the possible values for states and attributes

davesmeghead commented 1 month ago

Can we close this issue?

Joao-Sousa-71 commented 1 month ago

@davesmeghead Let's close it for now since I do not have all the automations converted yet , I sense it is just a matter of time to adapt. Still focus on the troubleshooting with the new version of the integration until it gets fully stable and I will get back to this topic after. Thx!