plaksnor / HASS-JablotronSystem

Jablotron component for Home Assistant
19 stars 12 forks source link

How it works #6

Open pavel-vrba1 opened 4 years ago

pavel-vrba1 commented 4 years ago

Hi, I would like to ask how to get this library working. I have Jablotron JA100 system and Home assistant running on Odroid XU4 device, connected via LAN to my home network. The question is how to "connect" JA100 with my Homeassistant device - via some cable (I see you mention some serial cable) or via LAN or via Jablotron's cloud app (and MyJablotron app). Could you please help me? Thanks, Pavel

marceldeklerk commented 4 years ago

Just connect your central unit with a regular usb cable to your hass device.

pavel-vrba1 commented 4 years ago

@marceldeklerk Thanks, I have found the USB port on the bottom of Jablotron box and connected it to my Homeassistant device. If I run dmesg | grep usb command it seems the Jablotron system is detected (see screenshot). Hassio I added a following section into configuration.yaml:

jablotron_system:
  port: /dev/hidraw0
  code: 1234

I replaced the number 1234 with a code I use to arm/disarm the alarm. I have restarted Hassio, activated PIR sensors by moving around the house but then nothing happened. I cannot see any new entities, sensors or devices related to Jablotron. What I am doing wrong? Also the instructions say that sensors should be shown on http(s)://domainname<:8123>/states but such a page does not exist - in my case it is http://192.168.1.151:8123/states but I get 404: Not Found error.

I can also see folowing error in the Log:

Logger: homeassistant.components.alarm_control_panel
Source: custom_components/jablotron_system/alarm_control_panel.py:24
Integration: Ovládací panel alarmu (documentation, issues)
First occurred: 10:39:43 (1 occurrences)
Last logged: 10:39:43
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 178, in _async_setup_platform
    await asyncio.wait_for(asyncio.shield(task), SLOW_SETUP_MAX_WAIT)
  File "/usr/local/lib/python3.7/asyncio/tasks.py", line 442, in wait_for
    return fut.result()
  File "/config/custom_components/jablotron_system/alarm_control_panel.py", line 24, in async_setup_platform
    async_add_entities([JablotronAlarm(hass, config)])
TypeError: Can't instantiate abstract class JablotronAlarm with abstract methods supported_features

Thanks guys for helping me, I am quite new to Hassio so obviously I am struggling even with easy things :)

Shamshala commented 4 years ago

More experienced noobie here :slightly_smiling_face:

About the error, if i remmember correctly, it's caused by an update in AlarmPanel since HA v0.103. Try to add the green lines from this ff52ddb to your alarm_control_panel.py file.

I don't know what about others but i had to use code with adminitrator privileges, otherwise i wasn't able to get sensor states (it's possible to use code just for a normal user in HA but then you have to run remotely F-Link with admin code simultaneously - unfortunately it'll disconnect the F-Link after some time and without admin code it stops reporting states in HA within 5 minutes. Another thing could be an absence of the right "bytes" in the integration code. I had to add few bytes to get some of my sensors to work - one of the ways to get them is to use Wireshark+USBPcap in combination with F-Link with admin privileges and by "trying everything" to record the USB communication (the integration should report missing codes in debug mode in HA's log but it didn't work for me that well).

pavel-vrba1 commented 4 years ago

@plaksnor, @Shamshala Guys, I have moved a bit forward but still not everything works perfectly. I can now see about 13 binary jablotron sensors in Home assistant, while in my house I have 12 magentic door/window sensors and 7 PIR movement sensors. Only 4 out of 13 binary sensors change state when I open/close windows, the other 9 haven't changed state at all.

The second issue is that I am still getting error in the log as reported above: Error while setting up jablotron_system platform for alarm_control_panel - Can't instantiate abstract class JablotronAlarm with abstract methods supported_features.

To me it seems it is some issue in the code itself although I am not a Python expert. As a result I do not see any alarm_control_panel in Home assistant related to Jablotron and thus cannot arm/disarm my alarm. @Shamshala I tried to add the green lines from ff52ddb as you suggested. It did not help either.

An ideas how to move forward? I can manage catching communication over USB but I do not know what bytes to look for and how to use them. Thanks.

Shamshala commented 4 years ago

I don't know Python either. :slightly_smiling_face:

Ad the green lines - that's a bit odd. Have you deleted the __pycache__ folder in the jablotron_system before restarting HA? Is the error in the log still the same?

Ad the missing sensors, as i've said before i had to add few bytes to the binary_sensor.py code in order to get them to work (you need to catch the "on" and "off" state)

In Wireshark you're looking for "URB_INTERRUPT out" and "URB_INTERRUPT in" and some sequences in HEX. Unfortunately i have only wired sensors so i'm sure just about this (ST = state, AA AA = address of the sensor): 55 08 00 ST AA AA Wireless should report the state by: 55 09 00 ST AA AA You need to add the state bytes to the line mentioned above and then your sensors should work.

EDIT: Sorry, sometimes there are also : 55 08 01 ST AA AA 55 09 01 ST AA AA

pavel-vrba1 commented 4 years ago

@Shamshala ok, I think I understand what I should do, I will give it a try in the evening. Just a question - does the alarm panel entitity appears in your Home assistant setup so that you can arm/disarm the Jablotron alarm from Home assistant? Thx.

Shamshala commented 4 years ago

Yes, alarm panel works for me. Unfortunately it seems like @plaksnor abandoned the integration, so it stopped working when v0.103 came out but after the modification from @mattsaxon ("the green lines") it works again even after v0.103. And actually, by some of the "sniffing" i was even able to add my second zone, for arming at home. :slightly_smiling_face:

EDIT: Well after i was done writting this post i realized one thing. YES, alarm panel works for me - I'm able to arm and disarm my system no problem. But worth to mention, despite i specified that it's required to enter my code everytime, alarm panel ignores the input. Doesn't matter if the code is right, wrong or empty, it dis/arms on click of a button - not much secure i suppose. So YES and NO :rofl: I'm in a process of debugging to solve the issue but i don't want others to use my admin code anyway so i plan to try to define a second code for a normal user. And i think other HA users don't have such issue (HA community forum), so it might not be your case.

pavel-vrba1 commented 4 years ago

@Shamshala So I tried again to add the lines from @mattsaxon's modification and I cleaned the python cache - I suppose that helped so I can now see alarm_control_panel.jablotron_alarm entity and I can arm and disarm the alarm :-))) If I will have more time I will try to wireshark the communication to get other sensors working. Anyway could you tell me what bytes did you add to binary_sensor.py? They might work for me as well.

Shamshala commented 4 years ago

if byte4 in (b'\xa0', b'\xa8', b'\x6d', b'\x75', b'\x79', b'\x7d', b'\x80', b'\x84', b'\x88', b'\x8c', b'\x90', b'\x94', b'\x98', b'\x9c'): :slightly_smiling_face:

EDIT: It looks almost like it simply uses bytes incremented by 4 between ON states (state off is incremented by 2 -> 7d = on, 7e = off). So you can also try take a guess by adding rest of the values between these.

EDIT2: btw can you also try to use this in your configuration.yaml to catch the "bytes". But it didn't work for me well.

logger:
  logs:
    custom_components.jablotron_system: debug
    custom_components.jablotron_system.alarm_control_panel: debug

Just out of curiosity. If you set both params to require the code for dis/arm your system, does it work for you or it ignores the input as well? => Ok, nevermind. I was investigating a bit and noticed those options are for to include a code in the packet if it's necessary to dis/arm system.

Thoky81 commented 4 years ago

@Shamshala So I tried again to add the lines from @mattsaxon's modification and I cleaned the python cache - I suppose that helped so I can now see alarm_control_panel.jablotron_alarm entity and I can arm and disarm the alarm :-))) If I will have more time I will try to wireshark the communication to get other sensors working. Anyway could you tell me what bytes did you add to binary_sensor.py? They might work for me as well.

Can you share the updated file ? I have added the green lines but its not working. Thanks

pavel-vrba1 commented 4 years ago

@Thoky81 I have added the bytes from "green lines" as well as the bytes @Shamshala suggested in his post but there is no change - I mean still only 4 out of my 13 or so jablotron sensors chage their state when opening/closing windows/doors. I have not find time to bebug the usb communication with Jablotron alarm yet.

@Shamshala: I have the alarm code in my cofig.yaml so when sending arm/disarm events it does not require the code any more. I will try the logger: thing, will see. You also said you were able to discover the second zone. What strings/bytes should I look for to discover that? :)

Thoky81 commented 4 years ago

So finally I made it. I can see the motion sensors and alarm control panel. But Arming/Disarming only with code.

Shamshala commented 4 years ago

@Shamshala: I have the alarm code in my cofig.yaml so when sending arm/disarm events it does not require the code any more. I will try the logger: thing, will see. You also said you were able to discover the second zone. What strings/bytes should I look for to discover that? :)

You have to have the code in your config in order to get status of your sensors :laughing:, not to mentioned it's marked as "required" so it shouldn't be even possible to start the integration without it.

It uses 80 02 0d XX. 90/a0 are used for dis/arming the main zone. Unfortunately i'm not able to disarm my second zone via the main zone (even though it's a subzone of the main zone) and it has a different byte for disarming so i have another thing in my todolist. (the panel has only one "Disarm" button and in the python there is only "one 'byte' to rule them all")

Thankfully, again @mattsaxon created a python for specifying whether or not the code should be entered by an user, so at least this is fixed for me. (but still the admin code though...) And even though i'm using this integration for quite some time, few days ago i noticed there isn't specified the "Pending" state (fixed now), nor the "Triggered"(this probably will take a bit of time). And it looks like the integration interrupts the alarm sound after few seconds it had been triggered (i have some guesses). Probably not a big deal if one has a silent alarm and it's connected to a security service of some sort but...). ........ Again out of curiosity, do you have a subzone which is manageable via disarming the main zone? (at any time) I think it should work like that but my installer was a noob who had told me it's impossible. So despite it's even in F-Link as a subzone, it has to be disarmed individually/separately. Not to mention I have also a physical button for another zone which is completely useless for me but yet in order to have buttons for my main and "second zone" I supposedly need this third one as well - basicaly my second zone are just magnets(in windows) for night time. But for God-knows what reason i have the third button for PIR sensors as well...

pavel-vrba1 commented 4 years ago

@Shamshala Hi, so I finally used Wireshark to sniff the communication and discovered ON states of all my wired magnetic sensors - these are the additional bytes I have to add to the Python code: b'\x7c, b'\x90, b'\x94, b'\x98, b'\x9c, b'\xa0, b'\xa4, b'\xa8' I confirm it uses increment by 4. Next step is to discover the PIR movement sensors - I have already noticed during sniffing the state change look like: 55 08 80 ST AA AA. However they are not added as binary sensors so I will have to figure out how to modify the Python code :)

Regarding the zones, I have two separate zones: 1) Garden house - there is a wireless magnetic sensor checking the door - this one is not discovered in HA, neither I can arm/disarm that zone from HA 2) House - there are wired magnetic sensors on doors/windows (all discovered) and PIR movement sensors (not discovered) - I can "arm home" this zone from HA, meaning the right button on a keyboard goes yellow so the alarm gets fired in any door/window gets opened (the PIR sensors do not cause an alarm). I am using this in "good night" automation - if I turn off the Xiaomi bedside lamp and it is after 10pm, it arms the alarm so there is no need to go from the sleeping room to Jablotron keyboard for arming :)

As you can see on a photo each zone is armed/disarmed separately on a Jablotron keyboard with its own physical buttons.

I am going to do some more Wireshark sniffing :) Jablotron

Shamshala commented 4 years ago

I think it should be OK to try to add the 80 to line 394 of binary_sensor.py and i assume it will pick the sensors as normal. (just guessing via phone 😛 ) It's interesting that it uses a little bit different code again. But i noticed this "sequence" as well (not as a sensor states reporting) - couldn't be caused by multiple sensors triggered at the same time?

Did you find the arming code for another zone? Btw: The byte needs to be pasted into one of these line 422 of alarm_control_panel.py

Ad the keyboard: Yep, that make sense to have two buttons for two separated zones. 😃

Shamshala commented 4 years ago

Any progress? :slightly_smiling_face:

Could you please provide me your HEX strings after 51 22 ? My Jablotron's backup battery start to fail and i noticed that i have to modify the Jablotron code again (zones are probably managed differently than i thought) Now i understand a little bit why @plaksnor used those state bytes in his code. I would like to try to modify the integration a hopefully do it more user-friendly but i have only two JA-100K units to test (more samples means more info :smile: ). Not to mention my zones are subzones of one main zone but you have two separate ones (which is different scenario, therefore perfect for variables). Any contribution is welcome.

EDIT: Also i'm looking for somebody with more than three zones. :slightly_smiling_face:

rampie commented 4 years ago

Hey, Could someone help me?

If i look to the command with dmesg | hid i get the following result: afbeelding

so i assume i need to add the following code: jablotron_system: port: /dev/hidraw3 code: xxxx (where xxxx is either a service code or a code to (de-)activate the zones

When i try this, i come up with the following error: ERROR (MainThread) [homeassistant.components.hassio] Component error: jablotron_system - Integration 'jablotron_system' not found.

anything i'm missing?

Shamshala commented 4 years ago

@rampie What about your own thread..? :slightly_smiling_face:

Is that from config check? (before restart of HA) If so, then restart it first without the config.yaml part for 'jablotron_system' (or comment it out) and then paste the config and restart it again.

rampie commented 4 years ago

@rampie What about your own thread..? 🙂

Is that from config check? (before restart of HA) If so, then restart it first without the config.yaml part for 'jablotron_system' (or comment it out) and then paste the config and restart it again.

OK https://github.com/plaksnor/HASS-JablotronSystem/issues/9

pavel-vrba1 commented 4 years ago

@Shamshala Hi, I've finally forced myself to sniff the communication to discover the other zone. Unfortunatelly, I cannot find the right bytes - neither 80 02 0d XX. 90/a0 for arming/disarming nor 51 22 XX YY. Could you please drop me an email to jumperr@protonmail.com so I can send you my wireshark logs? I do not want to put them here on a public place. Thanks.

Shamshala commented 4 years ago

That's odd.

Sure. I've sent you an email from 1564**@m.cz 🙂