lucacalcaterra / risco-mqtt-bridge

Risco Alarm panel to MQTT Server Bridge
MIT License
25 stars 9 forks source link

Armed command only arm Parition 1 #7

Closed fab33 closed 4 years ago

fab33 commented 5 years ago

Hi and thank you for your work. Everythings seems to works fine except one things : with MQTT when you send "armed", only the first parition is armed. Is it possible to have one topic for each partition ?

lucacalcaterra commented 5 years ago

It's manage only 1 partition , but only why i ve no time to test on multiple partition , so ... i must adapt the code. Soon i'll work on it

fab33 commented 5 years ago

Thank you, I will wait for it !

ekkesa commented 5 years ago

This will be absolutely awesome!!! Thank you for this - Looking forward to the multiple partitions. I have 4 I'd like to manage

fab33 commented 5 years ago

Any news for this enhancement ?

lucacalcaterra commented 5 years ago

Hi, not for now, i'm quite busy.. As soon as possibile i'll fix it

Il giorno sab 18 mag 2019 alle ore 15:22 Fabien Marchewka < notifications@github.com> ha scritto:

Any news for this enhancement ?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/lucacalcaterra/risco-mqtt-bridge/issues/7?email_source=notifications&email_token=AAGWZULUX4HQPNDMZWWOUD3PV77KNA5CNFSM4GMULXU2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODVWOSXY#issuecomment-493676895, or mute the thread https://github.com/notifications/unsubscribe-auth/AAGWZUKG4KMRYLRQY4ODGETPV77KNANCNFSM4GMULXUQ .

fab33 commented 5 years ago

@lucacalcaterra , before you made this change, is there a way to arm all partitions ?

lucacalcaterra commented 5 years ago

Yeah ! Before migrate to python , i'll fix this... I need time :-) and a panel with multiple partition to tests

pergolafabio commented 5 years ago

No multiple here :(

fab33 commented 5 years ago

Just find a workaround : https://github.com/lucacalcaterra/risco-mqtt-bridge/blob/bf9e0006ad593a0376ea3c1629a8dc3c86e9caf4/serverHandler.js#L234 remove 0: and it will work for all partitions. Or you can configure arm command with 0:armed 1:armed 2:armed and send it to the topic.

lucacalcaterra commented 5 years ago

@fab33 Thanks for you simple workaround... until i'll find time to implement multiple partitions

ekkesa commented 5 years ago

Hi, Have you found any time to perhaps look at the multiple partitions? It will be much appreciated.

Thank you!

ekkesa commented 4 years ago

Any progress on the multiple partitions? Alternatively, is it possible to create multiple instances of this for each partition and then manage it with scripts via Home Assistant?

ekkesa commented 4 years ago

Unfortunately the tweak of changing line 324 by removing the "0:" and prefixing it to the MQTT payload did not work for me. So, I tweaked the config.js and serverHandler.js and spun up 4 docker containers. I'm able to control the four partitions, but unfortunately when any one of the partitions are in a armed/partially armed state all show armed. So I will have to manipulate them via MQTT and not the alarm_panel_component in HA. At least a start so far.

lucacalcaterra commented 4 years ago

I should implement it... and others features requested... unfortunately now no time to follow the project due to other jobs that take a lot of time :-( If someone want fork and contribute... i'll happy to accept PR. Luca

ekkesa commented 4 years ago

Appreciate your effort - I had the coding skill I'd love to do it, unfortunately I believe I will make more damage than good. Hopefully we have a skilled user here somewhere.

swiergot commented 4 years ago

Just submitted a pull request. Seems to be working but needs more testing. Especially I'm not sure if/how it affects the integration with Home Assistant. Will try to look into it tomorrow.

ekkesa commented 4 years ago

Just submitted a pull request. Seems to be working but needs more testing. Especially I'm not sure if/how it affects the integration with Home Assistant. Will try to look into it tomorrow.

I'll be happy to test - Am I correct in I just have to replace the following files with those from your repo: app.js
panelPoller.js
serverHandler.js

Note: I'm running in docker on RPi

swiergot commented 4 years ago

@ekkesa Thank you for your interest. You are right. And please make sure to use new topics.

ekkesa commented 4 years ago

Hi,

Just tried that with the following docker compose:

version: '2.0' services: risco-mqtt-bridge: image: lucacalcaterra/risco-mqtt-bridge:armhf container_name: RiscoMQTTTest restart: unless-stopped volumes:

It spins up, logs in, and I can see it gets the status from the cloud. But it does not report it on MQTT. The logs show connected to MQTT and it states published messages to mqtt, but the 'armstatus' does not arrive for the partitions. It does report on the the detectors, ISONALARM and the event history. I changed the main topic from riscopanel to riscopaneltest.

When publishing on MQTT to, for example, riscopaneltest/armstatus/3/SET I receive the following error in the log:

info: arm/disarm command arrived warn: arm command not recognized

I tried the following commands to that topic in both upper and lowercase: arm, armed, partarm, partarmed, disarm, disarmed, partially, home_armed, but none worked.

Any suggestions?

swiergot commented 4 years ago

@ekkesa Are you missing app.js in your docker config?

ekkesa commented 4 years ago

Good catch! Now I feel like an idiot... :-)

Will fix it, and try again...

ekkesa commented 4 years ago

I fixed the app.js link and it is definitely now reporting the status of the different partitions via MQTT, but when I publish a 'SET' command it does not work. I receive this error in the log:

02-02-2020 17:24:55 info: message from mqtt arrived:RiscoHuisTest/armstatus/3/SET/partarmed 02-02-2020 17:24:55 info: arm/disarm command arrived 02-02-2020 17:24:55 warn: arm command not recognized

Not sure where I am going wrong...

ekkesa commented 4 years ago

I did some further testing.

armed - Working disarmed - Working partarmed - Not Working partially - Not Working armed_home - Working

weird, but hey I'm very happy!

Thank you so much - I will now see how well this integrates with HA.

swiergot commented 4 years ago

@ekkesa Thanks. I will look into partarmed, I'm not using it so I might have missed it. Integration with HA has been working fine for me. However I'm having some issues with the cloud itself. The user I created for this purpose stops working from time to time as if the PIN code got invalidated. Then I have to reassign the very same PIN code as admin and it starts working again.

ekkesa commented 4 years ago

I'm testing scripts currently, and now armed_home seems to not work anymore, even when submitting manually. I have noticed the polling interval is quite temperamental - too long and the session timeout too short and you get errors. I'm currently running on 30 seconds and it seems to hold up on the original code.

Not sure why the it does not recognise the partarmed/partially/armed_home command. I'll keep fiddling and post back here if I can find a pattern..

UPDATE: It was timing luck the previous time. A background process was arming my alarm for partially armed on a schedule. The partarmed is not being recognised in any of the forms.

Appreciate your work on this - Its really awesome!

UPDATE: It seems 'partially' does indeed work. I also noticed that one cant jump from partially armed to armed directly and vice versa. One has to go to disarm first. Something to keep in mind when scripting/automating. Perhaps something that can be added as en enhancement? *if partially armed and receive arm command, first issue disarmed, then issue armed command'

ekkesa commented 4 years ago

Another error: Trying to bypass detectors I receive the following error:

02-02-2020 18:33:53 info: message from mqtt arrived:RiscoHuisTest/dects/2/SET/bypass /app/app.js:147 case (topic.match(regexpart)[0]): ^

TypeError: Cannot read property '0' of null at MqttClient.mqttClient.on (/app/app.js:147:35) at emitThree (events.js:136:13) at MqttClient.emit (events.js:217:7) at MqttClient._handlePublish (/app/node_modules/async-mqtt/node_modules/mqtt/lib/client.js:987:12) at MqttClient._handlePacket (/app/node_modules/async-mqtt/node_modules/mqtt/lib/client.js:336:12) at work (/app/node_modules/async-mqtt/node_modules/mqtt/lib/client.js:292:12) at Writable.writable._write (/app/node_modules/async-mqtt/node_modules/mqtt/lib/client.js:302:5) at doWrite (/app/node_modules/readable-stream/lib/_stream_writable.js:428:64) at writeOrBuffer (/app/node_modules/readable-stream/lib/_stream_writable.js:417:5) at Writable.write (/app/node_modules/readable-stream/lib/_stream_writable.js:334:11)

swiergot commented 4 years ago

Sorry, it was a stupid mistake. It is now fixed in my repo, please have a look.

So I understand partial is working (except for your finding related to state transitions)? What about session timeouts?

ekkesa commented 4 years ago

I saw it drops a connection error is the polling interval is set above 60000ms, currently have it on 15000ms and it seems to be stable.

Also, I found that when sent two /SET command in quick succession it doesn't queue them, it completes the one it is busy with and discard the ones it received while busy. It seems to be per partition. E.g. I can send disarmed in parallel to all 4 partitions and it will complete them, but I cannot send disarmed and armed in a script without a delay (+-20s) between the commands.

*UPDATE: I tested the disable/bypass of detectors - It works 100%, Thx!

ekkesa commented 4 years ago

I noticed the alarm was not responding via mqtt and noticed this error.

10-02-2020 16:56:31 debug: Class Connection Constructor end, 10-02-2020 16:56:31 info: Connected to MQTT Server, 10-02-2020 16:56:36 debug: Logged...Response code is 302: OK, 10-02-2020 16:56:41 debug: ...site and Pin Code sent...Response code is 302: OK, 10-02-2020 16:56:46 debug: ...Cameras taken...Response code is 200 and no data error: OK, 10-02-2020 16:56:52 debug: ...Event History taken...Response code is 200 and no data error: OK, 10-02-2020 16:56:57 debug: ...Detectors taken...Response code is 200 and no data error: OK, 10-02-2020 16:57:02 debug: return null, overview empty!, 10-02-2020 16:57:02 debug: newarmstatus emitted, 10-02-2020 16:57:02 info: Arming status: [], 10-02-2020 16:57:02 debug: Init function for getting data from Cloud completed: OK, 10-02-2020 16:57:02 debug: polling started..., (node:1) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'detectors' of undefined, at RiscoPoller.riscoPoller.on (/app/app.js:102:62), at emitNone (events.js:106:13), at RiscoPoller.emit (events.js:208:7), at RiscoPoller.init (/app/panelPoller.js:34:10), at , at process._tickCallback (internal/process/next_tick.js:189:7), (node:1) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1), (node:1) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.,

I have recreated the container via docker-compose, but the issue persists. Any idea what might be causing it?

UPDATE: I see it also creates this error for other properties: " (node:1) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'parts' of null"

UPDATE2: I tested the unforked version too, and receive the same errors. I opened this issue.

swiergot commented 4 years ago

Could you please check if the credentials are still working? Just open a browser a try to log into Risco Cloud.

ekkesa commented 4 years ago

The credentials do work via Chrome when signing in.

Update: I also do not see any errors in the 'EVENT HISTORY' on the web interface.

ekkesa commented 4 years ago

I powered down the panel (Removing power adapter and battery) and restarted it - this seems to have addressed the issue. Still strange that the web interface worked, but the container didn't...

swiergot commented 4 years ago

It would be interesting to see the raw JSON coming from the server. Please let me know if it happens again.

ekkesa commented 4 years ago

Will do! Where can I harvest that for you should it happen again?

francois-dotnet commented 4 years ago

Hello @swiergot and @ekkesa , i have read through this thread and installed swiergot's fork/branch. I have 2 partitions and 4 groups (of which I only really use 2). I have also experimented with mancioshell's risco-mqtt-home-assistant. I never have problems receiving the statuses, etc. But I am unable to send commands successfully. I tried disarming and bypassing zones. I tried using a user only setup with one partition and two, I can't find any errors. Would anyone be willing to post their config and how they successfully sent commands? p-l-e-a-s-e :)

swiergot commented 4 years ago

@francois-dotnet Here is the bridge config, below is part of HA's configuration.yaml:

alarm_control_panel:

francois-dotnet commented 4 years ago

@swiergot Thanks, my configuration.yaml is the same except I have code_disarm_required: false and define a unique_id (which I intend to remove). ARM and DISARM seems to work now, but not ARM_HOME. My config.js is also the same except I have: onalarm: 'triggered', // If you use Home Assistant you must set to 'triggered' instead of onalarm: 'onalarm',

Anyone have an example to send bypass MQTT? Mine does not seem to be working:

  - platform: mqtt
    name: test_pir_bypass
    state_topic: "risco/dects/part0/8"
    value_template: "{% if value_json['filter'] == 'bypassed' %}bypass{% else %}unbypass{% endif %}"
    command_topic: "risco/dects/part0/8/SET"
    payload_on: "bypass"
    payload_off: "unbypass"
ekkesa commented 4 years ago

The issue of dropping connections seems to be back. @swiergot where do I scavenge those raw logs for you?

UPDATE: A restart of the container fixes the issue for a short while (few hours) - then it breaks again.

27-06-2020 18:26:16 debug: polling ..., 27-06-2020 18:26:56 debug: return null, overview empty!, 27-06-2020 18:26:56 debug: Polled...counter: 22, 27-06-2020 18:27:11 debug: polling ..., 27-06-2020 18:27:16 debug: ...Detectors taken...Response code is 200 and no data error: OK, 27-06-2020 18:27:20 debug: return null, overview empty!, 27-06-2020 18:27:20 debug: Polled...counter: 23, 27-06-2020 18:27:35 debug: polling ..., 27-06-2020 18:27:40 debug: ...Detectors taken...Response code is 200 and no data error: OK, 27-06-2020 18:27:45 debug: return null, overview empty!, 27-06-2020 18:27:45 debug: Polled...counter: 24, 27-06-2020 18:28:00 debug: polling ..., 27-06-2020 18:28:05 debug: ...Detectors taken...Response code is 200 and no data error: OK, 27-06-2020 18:28:10 debug: return null, overview empty!, 27-06-2020 18:28:10 debug: Polled...counter: 25, 27-06-2020 18:28:25 debug: polling ..., 27-06-2020 18:28:30 debug: ...Detectors taken...Response code is 200 and no data error: OK, 27-06-2020 18:28:35 debug: return null, overview empty!, 27-06-2020 18:28:35 debug: Polled...counter: 26, 27-06-2020 18:28:50 debug: polling ..., 27-06-2020 18:28:55 debug: ...Detectors taken...Response code is 200 and no data error: OK, 27-06-2020 18:28:59 debug: return null, overview empty!, 27-06-2020 18:28:59 debug: Polled...counter: 27, 27-06-2020 18:29:14 debug: polling ..., 27-06-2020 18:29:19 debug: ...Detectors taken...Response code is 200 and no data error: OK, 27-06-2020 18:29:24 debug: return null, overview empty!, 27-06-2020 18:29:24 debug: Polled...counter: 28, 27-06-2020 18:29:34 info: message from mqtt arrived:RiscoAlarm/armstatus/0/SET/disarmed, 27-06-2020 18:29:34 info: arm/disarm command arrived, 27-06-2020 18:29:34 info: message from mqtt arrived:RiscoAlarm/armstatus/1/SET/disarmed, 27-06-2020 18:29:34 info: arm/disarm command arrived, 27-06-2020 18:29:34 info: message from mqtt arrived:RiscoAlarm/armstatus/2/SET/disarmed, 27-06-2020 18:29:34 info: arm/disarm command arrived, 27-06-2020 18:29:34 info: message from mqtt arrived:RiscoAlarm/armstatus/3/SET/disarmed, 27-06-2020 18:29:34 info: arm/disarm command arrived, 27-06-2020 18:29:38 debug: user code is expired? : false, 27-06-2020 18:29:39 debug: polling ..., 27-06-2020 18:29:43 debug: user code is expired? : false, 27-06-2020 18:29:43 debug: user code is expired? : false, 27-06-2020 18:29:47 debug: ...Detectors taken...Response code is 200 and no data error: OK, 27-06-2020 18:29:50 debug: arm command result ok, 27-06-2020 18:29:53 debug: arm command result ok, 27-06-2020 18:29:55 debug: arm command result ok, 27-06-2020 18:29:55 debug: ...Control Panel State taken and overview not empty... OK, 27-06-2020 18:29:55 debug: Polled...counter: 29, 27-06-2020 18:29:55 debug: newarmstatus emitted, 27-06-2020 18:29:55 info: Arming status: ["partarmed","partarmed","disarmed","partarmed"], 27-06-2020 18:29:55 info: publish messages on MQTT Server, 27-06-2020 18:29:55 info: Status panel infos arrived, 27-06-2020 18:30:10 debug: polling ..., 27-06-2020 18:31:09 debug: user code is expired? : true, 27-06-2020 18:31:09 debug: ...Detectors taken...Response code is 200 and no data error: OK, 27-06-2020 18:31:13 debug: Logged...Response code is 302: OK, 27-06-2020 18:31:14 debug: ...Control Panel State taken and overview not empty... OK, 27-06-2020 18:31:14 debug: Polled...counter: 30, 27-06-2020 18:31:14 debug: newarmstatus emitted, 27-06-2020 18:31:14 info: Arming status: ["disarmed","partarmed","disarmed","disarmed"], 27-06-2020 18:31:14 info: publish messages on MQTT Server, 27-06-2020 18:31:14 info: Status panel infos arrived, 27-06-2020 18:31:18 error: Exception on arm/disarm command: TypeError: Cannot read property 'text' of undefined, 27-06-2020 18:31:29 debug: polling ..., 27-06-2020 18:33:22 debug: return null, overview empty!, 27-06-2020 18:33:22 debug: Polled...counter: 31, 27-06-2020 18:33:22 warn: Disconnected from cloud...relogin and init..., 27-06-2020 18:33:27 debug: Logged...Response code is 302: OK, 27-06-2020 18:33:37 debug: polling ..., 27-06-2020 18:33:47 debug: return null, overview empty!, 27-06-2020 18:33:47 debug: Polled...counter: 32, 27-06-2020 18:33:47 warn: Disconnected from cloud...relogin and init..., 27-06-2020 18:33:52 debug: Logged...Response code is 302: OK, 27-06-2020 18:33:57 debug: ...site and Pin Code sent...Response code is 302: OK, 27-06-2020 18:34:02 debug: polling ..., 27-06-2020 18:34:07 debug: ...Detectors taken...Response code is 200 and no data error: OK, 27-06-2020 18:34:12 debug: return null, overview empty!, 27-06-2020 18:34:12 debug: Polled...counter: 33, 27-06-2020 18:34:19 debug: ...site and Pin Code sent...Response code is 302: OK, 27-06-2020 18:34:20 debug: ...Cameras taken...Response code is 200 and no data error: OK, 27-06-2020 18:34:24 debug: ...Cameras taken...Response code is 200 and no data error: OK, 27-06-2020 18:34:27 debug: polling ..., 27-06-2020 18:34:28 debug: ...Event History taken...Response code is 200 and no data error: OK, 27-06-2020 18:34:29 debug: ...Event History taken...Response code is 200 and no data error: OK, 27-06-2020 18:34:32 debug: ...Detectors taken...Response code is 200 and no data error: OK, 27-06-2020 18:34:33 debug: ...Detectors taken...Response code is 200 and no data error: OK, 27-06-2020 18:34:36 debug: ...Detectors taken...Response code is 200 and no data error: OK, 27-06-2020 18:34:37 debug: return null, overview empty!, 27-06-2020 18:34:37 debug: Polled...counter: 34, 27-06-2020 18:34:42 debug: return null, overview empty!, 27-06-2020 18:34:42 debug: newarmstatus emitted, 27-06-2020 18:34:42 info: Arming status: ["disarmed","partarmed","disarmed","disarmed"], 27-06-2020 18:34:42 debug: Init function for getting data from Cloud completed: OK, (node:1) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'LogRecords' of undefined, at RiscoPoller.riscoPoller.on (/app/app.js:111:54), at emitNone (events.js:106:13), at RiscoPoller.emit (events.js:208:7), at RiscoPoller.init (/app/panelPoller.js:34:10), at <anonymous>, at process._tickCallback (internal/process/next_tick.js:189:7), (node:1) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1), (node:1) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code., 27-06-2020 18:34:52 debug: polling ...,

lucacalcaterra commented 4 years ago

fixed with @swiergot pr. I must test it and merge