eavanvalkenburg / sia

SIA alarm systems integration into Home Assistant
MIT License
48 stars 11 forks source link

New attribute for the Zone Entity: Message #37

Closed scorbacella closed 3 years ago

scorbacella commented 3 years ago

Describe the solution you'd like I'd like to have a new attribute of the zone entity called "Message" in order to use it in automations, such as push notifications, triggered from alarm events. This attribute should be filled with the message that the integration already catches from the data fild of the SIA string.

Additional context This is an axample of a SIA string from my alarm system: 5C6F005D"SIA-DCS"0595L0#123456[#123456|Nri1BA2^02-VX.INGRESSO AREA VOLUMETRICI^]_20:01:04,01-04-2021

And this is what I see in the debug log: 2021-01-04 20:04:21 DEBUG (MainThread) [pysiaalarm.base_sia_server] Parsed event: Content: #123456|Nri1BA2^02-VX.INGRESSO AREA VOLUMETRICI^]_20:01:04,01-04-2021, Zone: 1, Code: BA, Message: 2^02-VX.INGRESSO AREA VOLUMETRICI^, Concerns: Zone or point, Type: Burglary Alarm, Description: Burglary zone has been violated while armed, Account: 123456, Receiver: None, Prefix: L0, Timestamp: 2021-01-04 20:01:04, Length: 005D, Sequence: 0595, CRC: 5C6F, Calc CRC: 5C6F, Message type: Burglary Alarm, Encrypted Content: None, Full Message: "SIA-DCS"0595L0#123456[#123456|Nri1BA2^02-VX.INGRESSO AREA VOLUMETRICI^]_20:01:04,01-04-2021..

This is the text I would like to read in the attribute: 2^02-VX.INGRESSO AREA VOLUMETRICI^ (the best would be "02-VX.INGRESSO AREA VOLUMETRICI", but I hope to post-process the string in some way. I don't know exactly the meaning of the number just before the symbol "^" ).

Thanks Stefano

eavanvalkenburg commented 3 years ago

Just added this to the latest pre-release, check it out and let me know, it's called last_message

scorbacella commented 3 years ago

Fantastic, thanks a lot. I'm looking forward to use it! And thanks for adding also the "code".

scorbacella commented 3 years ago

Hi, I installed the v0.3.11-beta.3 but now I get this error:

gave error in user function: 'SIAAlarmControlPanel' object has no attribute 'add_attribute'.

I don't know if I can write here or I have to open a new issue Thanks

eavanvalkenburg commented 3 years ago

Just released a new beta, should be fixed.

scorbacella commented 3 years ago

Hi, I'm testing the beta 4. I'have 2 misfunctionality:

1) I get this error in the log 2021-01-21 22:24:50 DEBUG (MainThread) [pysiaalarm.aio.sia_server] Incoming line: 02001100180002977&7Z&DC(;yGHiYq 2021-01-21 22:24:50 WARNING (MainThread) [pysiaalarm.base_sia_server] Last line could not be parsed as a SIAEvent, line was: 02001100180002977&7Z&DC(;yGHiYq Is it an extra line sent by the alarm system? The SIA message is not encripted. Could it be related to the issue #42?

2) the new attributes sometime are not updated with the last received message. They discords with the state of the entity. For instance: zone 2 state: disarmed zone 2 last_code attribute: CL

Thanks in advance

scorbacella commented 3 years ago

update about 2) the attribute "last message" actually reports the message just before the last received message. So it always discord with the current state of the entity.

This is the log: 2021-01-28 23:08:41 DEBUG (MainThread) [pysiaalarm.aio.sia_server] Incoming line: B970005E"SIA-DCS"0596L0#123456[#123456|Nri3BR22^22-CM.PF.CUCINA AREA FINESTRE ^]_23:06:52,01-28-2021

2021-01-28 23:10:30 DEBUG (MainThread) [pysiaalarm.aio.sia_server] Incoming line: 0C5B004D"SIA-DCS"0599L0#123456[#123456|Nri3CL0^AREA FINESTRE ^]_23:09:26,01-28-2021

and I see:

entity zone 3: armed_away last_message: 22^22-CM.PF.CUCINA AREA FINESTRE ^ last_code: BR last_update: 2021-01-28T22:08:41.903051+00:00

eavanvalkenburg commented 3 years ago

hey, I think I know what causes that, but I'm currently focused on a new version anyway so will release that one early next week, should be solved then and in a much better way! It will now use the built-in event hub of HA so that each message that comes from the alarm system generates a Event in HA, you can then create automations for yourself easily just by listening to those events, instead of having to wait for a state change of one of the built-in entities (like the current setup), this will also allow you to react to codes that are not captured!

scorbacella commented 3 years ago

Thanks for the explanation. I'll try

scorbacella commented 3 years ago

Hi, if it can help, this is the event generate by the incoming SIA message, both the new_state and the old_state contain the same last_message string:

Event 47 fired 8:55 PM:

{ "event_type": "state_changed", "data": { "entity_id": "alarm_control_panel.2068_123456_1_alarm", "old_state": { "entity_id": "alarm_control_panel.2068_123456_1_alarm", "state": "disarmed", "attributes": { "code_format": null, "changed_by": null, "code_arm_required": true, "account": "123456", "ping_interval": "1 day, 0:00:00", "zone": 1, "last_message": [ "1^AREA VOLUMETRICI^" ], "last_code": [ "OP" ], "last_update": [ "2021-01-29T19:51:49.118892+00:00" ], "friendly_name": "2068 - 123456 - zone 1 - alarm" }, "last_changed": "2021-01-29T19:51:49.118654+00:00", "last_updated": "2021-01-29T19:51:51.065920+00:00", "context": { "id": "030332ad411d83e525338698170a6119", "parent_id": null, "user_id": null } }, "new_state": { "entity_id": "alarm_control_panel.2068_123456_1_alarm", "state": "armed_night", "attributes": { "code_format": null, "changed_by": null, "code_arm_required": true, "account": "123456", "ping_interval": "1 day, 0:00:00", "zone": 1, "last_message": [ "1^AREA VOLUMETRICI^" ], "last_code": [ "OP" ], "last_update": [ "2021-01-29T19:51:51.066153+00:00" ], "friendly_name": "2068 - 123456 - zone 1 - alarm" }, "last_changed": "2021-01-29T19:55:06.572563+00:00", "last_updated": "2021-01-29T19:55:06.572563+00:00", "context": { "id": "84abd3b5a7408c77ec361796519fd500", "parent_id": null, "user_id": null } } }, "origin": "LOCAL", "time_fired": "2021-01-29T19:55:06.572563+00:00", "context": { "id": "84abd3b5a7408c77ec361796519fd500", "parent_id": null, "user_id": null } }

eavanvalkenburg commented 3 years ago

I know, the new version I'm working on will do this!

eavanvalkenburg commented 3 years ago

Just created a release with this feature: v0.4.0-beta.1 check it out and let me know!

scorbacella commented 3 years ago

It works perfectly! Thanks for all the new features and also for the custom allowed_timeband :) Great job

eavanvalkenburg commented 3 years ago

good to hear! the allowed_timeband was already in the underlying package but the default was stricter, should I make that configurable?

scorbacella commented 3 years ago

It would be nice, anyway now it's quite easy to change the range directly in the hub.py

eavanvalkenburg commented 3 years ago

yeah, but the plan is to have this integration into the core of HA so then that workaround is no longer possible!

scorbacella commented 3 years ago

then, yes please! I need that feature... 1) my messages arrive with a delay due to the queue of messages (voice call, sms, ...) 2)the time of the alarm unit is not perfectly synced. Thanks a lot

scorbacella commented 3 years ago

Hi, I saw that the component is now released as HA core integration. Congratulations, great job. I'm currently using the v4 beta 2 and it works very fine for me. Just few question before updating the core of HA; 1) does the integration permit the configuration of the "allowed_timeband"? 2) Is the event hub still working for triggering automations based on custom sia messages? 3) In case of negative answer, can I still use the HACS beta even if I update the HA core? Thanks a lot.

eavanvalkenburg commented 3 years ago

yeah, through an option flow, you can set the ignore timestamp field. It indeed puts messages on the event bus of HA as well, slightly differently than before, but still. yeah if you have the custom component installed, that will be used, if you do decide to switch over, you should first delete the integration in HA, then uninstall in HACS, reboot and then install the official one. One other note, the current integration is only a alarm_control_panel, the binary_sensor and sensor should come in 2021.7