gjohansson-ST / sector

Integration to Sector Alarm for Home Assistant
35 stars 16 forks source link

email used as "changed_by" #135

Open dogmatic69 opened 2 years ago

dogmatic69 commented 2 years ago

Describe the bug Recently, not exactly sure when it started, but often the "changed_by" user is my email address which the integration seems to be taking from the integration config rather than the actual values in the logs. Nowhere is email configured as a user in home assistant so this should never be the case.

image image

Version 0.3.8

Expected behavior Use the information from sector alarm for showing state, don't blend with assumed data from login information or otherwise

Sector always has the "changed by" information as part of the audit trail for the alarm.

gjohansson-ST commented 2 years ago

On setup I collect the username of the user HA logs into sector with to use as default user for changing the alarm. Then when api calls fails I assume it's the default user who made it e.g. sets the default user as the changed_by.

It's not excellent but a way to deal with a crapy api in this case. An alterantive is to leave changed_by as it was until it can refresh but I got complaints on that too. So essentially stuck between two bad options.

dogmatic69 commented 2 years ago

There is no reason to set this value ever, all logs have the user information that changed things. This is like an audit of changes to the alarm system. Randomly setting values makes the data completely untrustworthy.

gjohansson-ST commented 2 years ago

I don't necessarily agree since the only time it's set manually is when done from HA and therefore we know which user it is. Anyway it adds complexity so I would agree with you it's better to clean this out and if sector api fails to respond with a proper user then so be it.

The problem with double state changes will remain so people will have to adjust their automations accordingly.

dogmatic69 commented 1 year ago

Not true, I simply set up a "user" in sector which is "home" with it's own passcode. So at least in my case it should never use that value as sector is returning a username. This worked perfectly fine before and was always the correct value.

In what case does sector not return a User that changed the alarm? This is part of the audit logs of what has happened to the alarm.

This is my automation:

service: notify.ios_devices
data:
  title: Alarm Notification
  data:
    url: /lovelace/security
  message: >
    {% set by = state_attr('alarm_control_panel.sector_alarmpanel_02831351',
    'changed_by') %}

    {% if by == "home" %}
      {% set by = "Home Assistant" %}
    {% endif %}

    {% set alarm = states('alarm_control_panel.sector_alarmpanel_02831351') %}

    {% if alarm == "disarmed" %}
      {% set alarm = "disarmed" %}
    {% elif alarm == "armed_home" %}
      {% set alarm = "armed (Home)" %}
    {% elif alarm == "armed_away" %}
      {% set alarm = "armed (Away)" %}
    {% endif %}

    The alarm has been changed to {{ alarm }} by {{ by }}.

And then I get messages like:

The alarm has been changed to <state> by <my-sector-alarm-account-email>