Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alarm state notifications fire constantly #43

Closed
dogmatic69 opened this issue Dec 26, 2021 · 5 comments
Closed

Alarm state notifications fire constantly #43

dogmatic69 opened this issue Dec 26, 2021 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@dogmatic69
Copy link

Overview

  • Seems like data from sector is not reliably set in the state
  • At some random point it is correctly set resulting in wrong automations triggered
  • Wrong data used in notifications (eg: User A turned off the alarm, when actually it was User B)
  • Seems like the data in sector API is correct (according to my expectations at least)

Details / debugging

I've set up an automation to notify when the state changes and it fires constantly without any state changes. It works correctly when state does change, but through the day there can be 0-{n} extra updates due to nothing. This makes it impossible to use as a reliable indication of the alarm state change.

Automations

Auto enable at 21:00

  - id: auto-arm-alarm
    alias: Auto Arm Alarm
    trigger:
      platform: time
      at: "21:00:00"
    action:
      - service: alarm_control_panel.alarm_arm_home
        entity_id: alarm_control_panel.sector_alarmpanel_XXXXXXX

Notify on state change

automation:
  - alias: Alarm State Change
    id: alarm-state-change
    initial_state: true
    trigger:
      platform: state
      entity_id: alarm_control_panel.sector_alarmpanel_XXXXXXX
    action:
      - service: notify.ios_devices
        data:
          title: "Alarm Notification"
          message: ".... whatever ...."

Logs

So added some debugs in the code and I see this when the rogue notification is sent:

Initial normal update

_alarmstatus is constant, but watch _changed_by

2021-12-26 14:31:55 DEBUG (MainThread) [custom_components.sector] Info retrieved successfully URL: https://mypagesapi.sectoralarm.net/api/Panel/GetPanelStatus?panelId=xxxxx
2021-12-26 14:31:55 DEBUG (MainThread) [custom_components.sector] request status: 200
2021-12-26 14:31:55 DEBUG (MainThread) [custom_components.sector] OLD self._alarmstatus = 1
2021-12-26 14:31:55 DEBUG (MainThread) [custom_components.sector] self._alarmstatus = 1
2021-12-26 14:31:55 DEBUG (MainThread) [custom_components.sector] Info retrieved successfully URL: https://mypagesapi.sectoralarm.net/api/Panel/GetLogs?panelId=xxxxxx
2021-12-26 14:31:55 DEBUG (MainThread) [custom_components.sector] request status: 200
2021-12-26 14:31:55 DEBUG (MainThread) [custom_components.sector] self._changed_by = home
2021-12-26 14:31:55 DEBUG (MainThread) [custom_components.sector] Finished fetching sector_api data in 1.833 seconds (success: True)

Timeout error?

(why does it say "successful" if there was a timeout).

2021-12-26 14:33:10 ERROR (MainThread) [custom_components.sector] Timed out when connecting to Sector
2021-12-26 14:33:10 DEBUG (MainThread) [custom_components.sector] Info retrieved successfully URL: https://mypagesapi.sectoralarm.net/api/Panel/GetLogs?panelId=xxxxxxx
2021-12-26 14:33:10 DEBUG (MainThread) [custom_components.sector] request status: 200
2021-12-26 14:33:10 DEBUG (MainThread) [custom_components.sector] self._changed_by = home

Rogue update triggered by the next request

I'm assuming something happened due to the last timeout but now the _changed_by has changed.

2021-12-26 14:34:14 DEBUG (MainThread) [custom_components.sector] Info retrieved successfully URL: https://mypagesapi.sectoralarm.net/api/Panel/GetPanelStatus?panelId=xxxx
2021-12-26 14:34:14 DEBUG (MainThread) [custom_components.sector] request status: 200
2021-12-26 14:34:14 DEBUG (MainThread) [custom_components.sector] OLD self._alarmstatus = 1
2021-12-26 14:34:14 DEBUG (MainThread) [custom_components.sector] self._alarmstatus = 1
2021-12-26 14:34:14 DEBUG (MainThread) [custom_components.sector] Info retrieved successfully URL: https://mypagesapi.sectoralarm.net/api/Panel/GetLogs?panelId=xxxx
2021-12-26 14:34:14 DEBUG (MainThread) [custom_components.sector] request status: 200
2021-12-26 14:34:14 DEBUG (MainThread) [custom_components.sector] self._changed_by = Annie
2021-12-26 14:34:14 DEBUG (MainThread) [custom_components.sector] Finished fetching sector_api data in 4.676 seconds (success: True)

Looking at the logs from GetPanelHistory endpoint the following is two latest events:

0: {Time: '2021-12-26T10:05:51', EventType: 'disarmed', User: 'Annie', Channel: '', LockName: ''}
1: {Time: '2021-12-25T21:00:22', EventType: 'partialarmed', User: 'home', Channel: 'App', LockName: ''}

Last night it was set partial armed by automation at 21:00, this morning disabled by Annie at 10:05. Yet all the logs show the user who last changed was home (this is the user I set up for HA that did arm the system). Then somehow at 14:34 (~4 hours later) it gets the right user (Annie) has changed resulting in a notification.

Note to self for debugging I used this in the browser:

await fetch('https://momentjs.com/downloads/moment.min.js')
    .then(response => response.text())
    .then(text => eval(text))
a = await fetch('https://minasidor.sectoralarm.se/Panel/GetPanelHistory/xxxxx')
b = await a.json()
c = b.LogDetails.map(a => ({...a, Time: moment(a.Time).format()}))
@gjohansson-ST
Copy link
Owner

Would be happy to have a look at it. Just to say first the api from Sector is not very nice and therefore as you already spotted you can and will get several timeouts. To collect all the data there is several requests and therefore you might get a timeout on one and next one is fine.

If you are not can you run the last beta available and see if it changes something for you. The problem with the incorrect state changes should be fixed.

@gjohansson-ST gjohansson-ST self-assigned this Dec 27, 2021
@gjohansson-ST gjohansson-ST added the bug Something isn't working label Dec 27, 2021
@dogmatic69
Copy link
Author

Ye I can try upgrade it, did you manage to make the changes from my other PR (to remove need to enter code for arming).

@gjohansson-ST
Copy link
Owner

Yes. It's not necessary to submit a code for arming if you have it set in the config for the integration.

@dogmatic69
Copy link
Author

I've installed the latest beta with HACS. Will run for a few days and report back

@gjohansson-ST
Copy link
Owner

Solved in latest release v0.3.4

Repository owner locked as resolved and limited conversation to collaborators Jan 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants