Closed jjsapido closed 5 years ago
Hi no, the cube is currently not supported. But as you see already incoming attribute reports it should be easy to create a device file in custom components. Let me know if you need help or if I should send you a template. Thanks
Yes thanks I need some help to start out..
this is an example log from journalctl -u home-assistant@homeassistant.service -f
Sep 23 16:23:39 : 2018-09-23 16:23:39 DEBUG (MainThread) [zigpy.zcl] [0xf27a:3:0x000c] Attribute report received: 65285=500, 85=59.97000503540039
Sep 23 16:23:43 : 2018-09-23 16:23:43 DEBUG (MainThread) [bellows.uart] Status _send_task.done: False
Sep 23 16:23:43 : 2018-09-23 16:23:43 DEBUG (MainThread) [bellows.uart] Data frame SEQ(4)/ReTx(0): b'4576b1ed542e14a059964b25ab55927263945d5912316f939dcc3689dd353fe9557e'
Sep 23 16:23:43 : 2018-09-23 16:23:43 DEBUG (MainThread) [bellows.uart] Sending: b'8520dd7e'
Sep 23 16:23:43 : 2018-09-23 16:23:43 DEBUG (MainThread) [bellows.ezsp] Application frame 69 (incomingMessageHandler) received
Sep 23 16:23:43 : 2018-09-23 16:23:43 DEBUG (MainThread) [bellows.zigbee.application] pulled incomingMessageHandler
Sep 23 16:23:43 : 2018-09-23 16:23:43 DEBUG (MainThread) [zigpy.zcl] [0xf27a:2:0x0012] ZCL request 0x000a: [[<Attribute attrid=85 value=<zigpy.zcl.foundation.TypeValue object at 0x550d7e70>>]]
Sep 23 16:23:43 : 2018-09-23 16:23:43 DEBUG (MainThread) [zigpy.zcl] [0xf27a:2:0x0012] Attribute report received: 85=75
I got the following: clusters are 0x000c for analogInput (rotation) and 0x0012 for tap/flip/...
0x000c returns two attributes: 65285: (always set to 500) and 85: degrees of rotation
0x0012 returns one attribute 85: an integer value which may be 0 for shaking, <90 for 90degree flip, 100-160 for 180 flip, 256 for slide, and 500+ for double tap
i tested 0x0012 85 codes and they seem reliable over about 1000 attempts :)
finally the device has 3 endpoints 0x0012 works on endpoint 2 0x000c works on endpoint 3
im actually stuck with this:
zha_new:
usb_path: /dev/ttyUSB1
database_path: /home/homeassistant/.homeassistant/configuration/zigbee.db
device_config:
"00:15:8d:00:01:14:82:c7-2":
type: binary_sensor
#type: sensor
in_cluster: [0x0000, 0x0012, 0x0003]
#out_cluster: [0x0012]
config_report:
- [0x0012, 85, 60, 3600, 5]
#template: "lumi_sensor_wleak_aq2"
"00:15:8d:00:01:14:82:c7-3":
#type: binary_sensor
type: sensor
in_cluster: [0x0000, 0x0003, 0x000c]
out_cluster: [0x000c]
config_report:
- [0x000c, 85, 60, 3600, 5]
- [0x000c, 65285, 60, 3600, 5]
still no luck and no response from HASS gui.. i see the sensor but their state is always unknown and not updated
thanks for help
Update... following your suggestion of a custom component a played a little and got this working..
configuration.yaml is now:
zha_new: usb_path: /dev/ttyUSB1 database_path: /home/homeassistant/.homeassistant/configuration/zigbee.db device_config: "00:15:8d:00:01:14:82:c7-2": template: "lumi_sensor_cube" "00:15:8d:00:01:14:82:c7-3": template: "lumi_sensor_cube"
and made the attached custom_component on the following premises: I'm not able to parse two attributes (i.e. 85 and 65285) at the same time, so I ended up by only parsing attribute 85 and discriminating on the endpoints in order to have two sensor, one with rotation value and another for flip and taps..
not the best code for sure, but it works now.. the two sensors have the attribute "85 val" correctly updated.
Still need help on
any help is welcome
Hi, As this device has no real state (maybe battery) you should create events, Do you need the rotation endpoint, I think the Xiaomi gateway also has only the flip-90/flip-180/etc catching both attribute records is tricky and not needed if 65285 never comes alone.
I would do something like :
if value >= 500:
event= "double tap"
elif value >=256;
event = "slide"
elif value >=100
event = " flip_180"
elif value >0:
event= "flip_90"
else value == 0:
event = "shake"
and send this as an event.
What you want to see as sensor state? You can write this labels also to _state, but it's not really a state. And as you already stated you need to reset the state after x seconds. Thus, for automation an event is much easier, For visibility of whats happening the _state attribute is nicer, but you need also to wait until you can flip_90 when you did a flip_90
What kind of attributes you receive, that you want to pause receiving it for 10 sec? Some kind of timer you find in the binary_sensor/zha_new.py. It sets a variable and calls a function in x sec to reset it. you can check this variable and then just return if its still valid.
If the device has two endpoint this should be handled separate. You can create an virtual device in HASS and mix them together.
thanks, actually "fake states" are working and I managed to both use them in sample automation, but i need your help to set up event firing...
i cant really understand how to setup and fire events. Is it enough to fill the following variables in the custom component file? Or how can i access them?
entity.entity_id = // it probably yet exist? entity.channel': must be set? entity.command: can be custom, like "rotation" (for 65285 case 85 attribute payload) and "move" (for default 85 attribute payload) entity.up_down: can be omitted? entity.step: attribute real value for rotation or state label?
or i can keep going with the "fake state", reset it in a default state every time and just trigger self.schedule_update_ha_state()
i'm kinda confused
Hi, please look at the preview branch for the binary_sensor code for how to send event's. It's simple
mmmm.. is that enough from inside the new device?
value = #result of attribute parsing
command = 'cube_rotation'
event_data = {
'entity_id': entity.entity_id,
'channel': 'Level',
'command': command
'step': value
}
entity.hass.bus.fire('click', event_data)
That should do it.
is it the right output ?
2018-09-29 20:13:32 INFO (MainThread) [homeassistant.core] Bus:Handling <Event cube_event[L]: step=slide, channel=Level, entity_id=sensor.lumi_lumisensor_cube_011482c7_2, command=cube_slide>
I think you can even remove the step and channel and just use command, The entity_id and command are the information you want to process in Hass. Step and channel are more for devices where you have different channels like brightness or color_temp.
Thanks, the device actually works and events are properly fired Moreover, events are correctly managed by an appdaemon automations.. thanks for all your help if you are interested and explain me how/where to put the code, I will add the new device to your library
That would be nice. Adding your file to my repo is easy. Just add your file with
git add filename
Then commit
git commit
And push it to your github fork
git push
Inside the github gui you can create a pull request with the differences from your to my repo. From there I can pick it up to add it.
i think I'm ok.. please let me know if everything is correct :)
hi, why you do ``DOMAIN = 'cube_event'
and can you check if you receive attribute 0xff02:or 0xff01 with the battery information and add the matching attribute parsing to get the battery
Many Thanks
About the row
DOMAIN = 'cube_event'
I can remove it, I hadn't clear from examples if a domain should be set or not.. If it is not useful for initialisation , the statement can be removed.
Regarding cluster 0xff02 or 0xff01, I had no luck trying to grep any info on them from the log file.. nothing with that cluster is shown on debug log of zigpy.zcl
I also checked how battery info are collected in a custom groovy component made for SmartThings. It looks they catch battery info on cluster 0x0000 with the following command:
getBatteryResult(cluster.data.get(6))
I confirm something is received on cluster 0x0000 with attribute 65281 : 65281=b'\x01!\xa9\x0b\x03(\x16\x04!\xa8C\x05!\xbd\x01\x06$\x06\x00\x00\x00\x00\n!\x00\x00\x97!\x00\x00\x98!\xfd\x0f\x99!@\x0b\x9a!\x03\x00'
nonetheless I have no idea how to parse it .. any help?
right, 0xff01=65281 Please take a look at the lumi_sensor_magnet.py file. There you can grab the code for attribute 0xff01.The attribute value is a list of different values, mostly unclear, but one of them is the battery voltage and another one the network-id of the parent. The Domain is already set in the man zha_new file. Not sure if it makes any difference, if you redefine it. You may check if anything change if you remove it.
I tried but no success..
I edited the endpoint_id 1 config as follow: ` if selector in ['lumi_sensor_cube', ] and self.endpoint_id == 1: config = { "config_report": [ [0x0000, 5, 60, 3600, 5], [0x0000, 65281, 60, 3600, 5], ],
# "out_cluster": [],
"type": "sensor",
}
self.add_input_cluster(0x0000)
`
but after I added the device config for new endpoint_id (1) in configuration.yaml
device_config: ... "00:15:8d:00:01:14:82:c7-1": template: "lumi_sensor_cube"
everything stopped working.. Also the other two sensor (flip/rotation)
If I remove the endpoint_id1 device from configuration.yaml everything works again no idea why, and I also have no logs from zha_component when I activate endpoint1 ideas?
Sorry. There is no need to add attribute reporting. You already receive reports for cluster 0/0xff01. I was talking about the parser. Not sure who told you to modify the device config either. All you need to do is cop/ paste the parser for 0xff01 from lumi_sensor_magnet.py to your file. You may read some other thread where I mentioned this?
I don't understand
You already receive reports for cluster 0/0xff01.
I'm not sure at this point.. I identified other commands by looking at zigpy/zcl debug log in hass. I can't identify any 0xff01 command/cluster on logs
I indeed found that about every hour is sent the following
Oct 14 08:22:34 : #033[36m2018-10-14 08:22:34 DEBUG (MainThread) [zigpy.zcl] [0xf27a:1:0x0000] Attribute report received: 65281=b'\x01!\xb3\x0b\x03(\x15\x04!\xa8C\x05!\xbd\x01\x06$\x01\x00\x00\x00\x00\n!\x00\x00\x97!\x00\x00\x98!k\x10\x99!\x99\x0b\x9a!\x03\x00'#033[0m
from the log file tag:[0xf27a:1:0x0000]
it seems to me that the message is sent on endpoint 1, cluster 0x0000, attribute 65281.
I actually have no listener (apparently) on endpoint1, since other two endpoints are explicitly defined in configuration.yaml
device_config:
"00:15:8d:00:01:14:82:c7-2":
template: "lumi_sensor_cube"
"00:15:8d:00:01:14:82:c7-3":
template: "lumi_sensor_cube"
The reason for this choice is that otherwise sensors aren't added correctly to home assistant, neither they are processed with the correct custom template.
Given those premises: 1 I don't understand why you keep referring to 0xff01 2 No idea why you think I'm already receiving report from 0/0xff01 3 I tried to cut and paste only parser for 0xff01 from lumi_sensor_magnet.py but I can't understand how it could be sufficient on his own.
1) 0xff01 = 65281 2) you see this: ``Oct 14 08:22:34 : #033[36m2018-10-14 08:22:34 DEBUG (MainThread) [zigpy.zcl] [0xf27a:1:0x0000] Attribute report received: 65281=b'\x01!\xb3\x0b\x03(\x15\x04!\xa8C\x05!\xbd\x01\x06$\x01\x00\x00\x00\x00\n!\x00\x00\x97!\x00\x00\x98!k\x10\x99!\x99\x0b\x9a!\x03\x00'#033[0m which is attribute 65281(=hex ff01) on cluster 0 and endpoint 1 3) you bind the endpoint1/cluster0 during the device init.
can you try to use lumi_sensor_cube.py as your device file? It just adds the handler for attribute 65281
I used preview build (https://github.com/Yoda-x/ha-zha-new/tree/preview) with the file you posted yesterday and (nearly) everything works fine with Elelabs USB and the Aqara Cube (MFKZQ01LM). Thanks a lot!
What doesn't work for now :
Rotation is now working fine. I found how to double tap: it's the entire cube that must be tapped twice. I can't get the battery level. This is my new version: https://gist.github.com/flechaig/bf9710bfcf8252d6abc17f730e821cb5#file-lumi_sensor_cube_aqgl01-py Please try and review. Thanks.
Hi,
thanks for the update.
about the battery. Can you remove all the out_cluster lines from def _custom_endpoint_init:
"out_cluster": [0x0000, 0x0003, 0x0004, 0x0005, 0x0012, 0x00019]
and restart.
As you only receive attibute report (in_cluster), this is unneeded and may create problems parsing attributes.
Please check if battery works after removing and restart.
Otherwise looks good,
- 0xff01 = 65281
- you see this: ``Oct 14 08:22:34 : #33[36m2018-10-14 08:22:34 DEBUG (MainThread) [zigpy.zcl] [0xf27a:1:0x0000] Attribute report received: 65281=b'\x01!\xb3\x0b\x03(\x15\x04!\xa8C\x05!\xbd\x01\x06$\x01\x00\x00\x00\x00\n!\x00\x00\x97!\x00\x00\x98!k\x10\x99!\x99\x0b\x9a!\x03\x00'#33[0m which is attribute 65281(=hex ff01) on cluster 0 and endpoint 1
- you bind the endpoint1/cluster0 during the device init.
can you try to use lumi_sensor_cube.py as your device file? It just adds the handler for attribute 65281
1,2,3 YES but.. I don't have that sensor available on homeassistant. As it happens with other sensors associated unless I explicitly declare endpoint in configuration.yaml
so.. when i add the lines
"00:15:8d:00:01:14:82:c7-1":
template: "lumi_sensor_cube"
in configuration yaml, the new sensor (pointing to endpoint1) is added to home assistant AND nothing work wnymore, neither the new sensor nor the two others.. they start working again as soon as i remove enpoint1 declaration in configuration.yaml
ps I actually have empty outcluster... i.e., = [] I'm trying commenting them out
I removed out_cluster lines, but still no battery level.
can you provide a full debug log and the zigbee.db? If it's only the battery not working it's a not big issue. You will see quickly when the battery is empty. @jjsapido No need to use templates or configurations. If the name of the py file matches the model name, with dots and blanks replaced by underscores, the file gets automatic used.
Hello! Trying to use Aqara cube aqgl01 with script lumi_sensor_cube.py provided by Yoda-x. It works good until the next reboot of HA. After reboot, I need again to pair cube with zha_new. This somehow helps zha receive events from cube again...until next reboot. I feel that zha do not recognize sensor fully, just partly. After reboot, it stops listening this device. I am really fresh to HA, python and zigbee and therefore cannot find problem myself. Any ideas?
@alex-v-g : can you provide the debug logs for the startup. This should not happen, as zha reads the saved devices out of zigbee.db. can you provide also your config? Thanks
Shaked cube and found following in the zha_new log:
2018-11-07 22:35:16 DEBUG (MainThread) [custom_components.zha_new] dummy parse_attribute called with (<Entity None: None>, 85, 2, 'lumi.sensor_cube.aqgl01') {} 2018-11-07 22:35:17 DEBUG (MainThread) [custom_components.zha_new] dummy parse_attribute called with (<Entity None: None>, 85, 0, 'lumi.sensor_cube.aqgl01') {}
Update: Found also that after each reboot I have in log info: Attempt to install https://github.com/Yoda-x/bellows/archive/master.zip#bellows==0.7.4. Never seen message whether it was successfull or not. So have a feeling that maybe bellows are not in required version.... I am using Hassio and not really sure how to check or force update. I see some data for bellows 0.7.4 in config/dev folder, which, as I think is a buffer for installation of required packages. Is it normal to have installation of bellows each reboot?
can you copy the file lumi_sensor_cube.py to lumi_sensor_cube_aqgl01.py. And why you use all the templates? Tradfri bulbs and dimmer are auto detected.
Thanks
Thanks, I will try when return home.... do you have idea about installation of bellows 0.7.4 every reboot - is it normal?
It should install bellows just once, but I don't use hassio, it may different. You see the same for zigpy? It should also use my github version. You should also try the version from @flechaig, as he has added support for your device
Thanks
I have tried @flechaig file, but it did not work at least from the first run, but I managed to start using cube by using your script. Regarding zigpy: installation of this I have never seen in logs,... maybe if first required installation fails, the second will not start? Anyway zha_new working for me with: xiaomi aqara switch button, Hue bulb, 1 ikea bulb E27, Xiaomi aqara motion sensor, temperature Xiaomi aqara sensor working perfectly. Cube is working until reboot, 3 GU10 trådfri bulbs lost connection after first reboot yesterday, will try to get them work today....
@Yoda-x - I have followed your advise and magic! Everything works even after reboot. Trådfri Gu10 bulbs - I was struggling to see them in HA and still be connected to Trådfri motion control. After 3-4 pairing with remote/reset- magic happened and they are both in HA and with motion control. Thanks for help and for your zha_new. Looking forward to buy more sensors/ lamps and make whole house smart:)
added to master, closing ticket
Is the Mi Cube supported yet.. I see it sending frames in debug and it also look connected with my HUSBZB-1. I see in home assistant log the following:
actual configuration.yaml:
I set cluster 0x0012 as it seems correct for MultistateInput cluster.
Is my configuration wrong or the cube not supported yet? Do I have to setup a custom_component ?
Thanks for hints