Smanar / Domoticz-deCONZ

deCONZ plugin for Domoticz (Zigbee application)
GNU General Public License v3.0
36 stars 27 forks source link

Support for Ikea Starkvind #143

Closed arjannv closed 1 year ago

arjannv commented 1 year ago

I think that the change in DeConz for the Starkvind requires an update from this plugin. https://github.com/dresden-elektronik/deconz-rest-plugin/pull/6124

It now reports as a new ZHAAirPurifier type, while Domoticz-deCONZ only supports the ZHAAirQuality type.

Smanar commented 1 year ago

Ha yes right, can you try the beta branch ? Have added a widget to control the ventilation (with fan icon) and add support for the same than for ZHAAirQuality for the Starkvind too.

arjannv commented 1 year ago

Thanks for the quick response! I will give it a try. For your information: there seems to be an error on line 138 of widget.py _type should by _Type I think.

Smanar commented 1 year ago

For your information: there seems to be an error on line 138 of widget.py _type should by _Type I think.

Exactly, thx ^^, this is untested yet, will be for keypad support

Have too edited the code accoding to

Expose attribute 0x0004, which reports PM2.5 in µg/m³, as state.pm2_5 (instead of state.airqualityppb);

There is so much usefull information in the json, but idk which one are the more usefull to be used as widget too.

arjannv commented 1 year ago

I've tried the update. I'm seeing two devices in Domoticz. The things I found so far:

Edit: Maybe the unresponsive fan switch is because of the way the DeCONZ api reports the Starkvind? It is split in two devices:

From the PR: https://github.com/dresden-elektronik/deconz-rest-plugin/pull/6124#issuecomment-1171536856 { "config": { "filterlifetime": 256728, "ledindication": true, "locked": false, "mode": "auto", "on": true, "reachable": true }, "ep": 1, "etag": "fea6623ea3909029409fed7a6224e60b", "lastannounced": null, "lastseen": "2022-06-30T18:19Z", "manufacturername": "IKEA of Sweden", "modelid": "STARKVIND Air purifier", "name": "Starkvind", "state": { "deviceruntime": 212939, "filterruntime": 210486, "lastupdated": "2022-06-30T18:19:46.177", "replacefilter": false, "speed": 20 }, "swversion": "1.0.033", "type": "ZHAAirPurifier", "uniqueid": "cc:86:ec:ff:fe:6d:30:11-01-fc7d" } and { "config": { "on": true, "reachable": true }, "ep": 1, "etag": "74eb5d8558a3895a39a3884189701c99", "lastannounced": null, "lastseen": "2022-06-30T18:20Z", "manufacturername": "IKEA of Sweden", "modelid": "STARKVIND Air purifier", "name": "Starkvind", "state": { "airquality": "excellent", "lastupdated": "2022-06-30T18:18:26.205", "pm2_5": 8 }, "swversion": "1.0.033", "type": "ZHAAirQuality", "uniqueid": "cc:86:ec:ff:fe:6d:30:11-02-fc7d" }

Smanar commented 1 year ago

Harf, haven't see it use 2 entries.

Have updated the code again, you can update with "git pull" Can you remove the previously created devices and reload the plugin (domoticz/hardware/deconz/update) ?

The sensor value is still in ppb. Acc. to the change in deConz, the new value is in µg/m³. Can I change it manually to µg/m³?

You can, but I have too updated the code, problem is idk how deconz will react at character "µ"

Maybe it's also nice to add the LED disable switch 0x0003 and the replace filter state 0x0001. These are not showing in Phoscon, only buried deep in the DeCONZ gui. So it will be nice to have these available in Domoticz instead

You have a direct acces to the api in domoticz (to see or write values), on Domoticz/Custom/Deconz/Sensor.

If the speed still not working can you make a try with the debug "debug info only" enabled ?

arjannv commented 1 year ago

Hi Smanar, thanks for all the work so far.

Can you remove the previously created devices and reload the plugin (domoticz/hardware/deconz/update) ?

I've removed all devices related to the Starkvind. Now it created a Fan switch and a Group switch with the same functionality (but not working), but not a new PM2.5 sensor..

You can, but I have too updated the code, problem is idk how deconz will react at character "µ"

I can add a custom virtual sensor with the character "µ", could also change the originally created sensor. However, it didn't create a new sensor after removal.

Unfortunately the fan switch still doesn't work. When selecting a mode it gives this in the logs: 2023-01-17 08:55:55.866 DeConz Hub: onMessage called 2023-01-17 08:55:55.867 DeConz Hub: ### WebSocket Data : {'attr': {'id': '153', 'lastannounced': None, 'lastseen': '2023-01-17T07:55Z', 'manufacturername': 'IKEA of Sweden', 'modelid': 'STARKVIND Air purifier', 'name': 'PM2.5 Slaapkamer', 'swversion': '1.0.033', 'type': 'ZHAAirPurifier', 'uniqueid': '2c:11:65:ff:fe:b0:88:39-01-fc7d'}, 'e': 'changed', 'id': '153', 'r': 'sensors', 't': 'event', 'uniqueid': '2c:11:65:ff:fe:b0:88:39-01-fc7d'} 2023-01-17 08:55:55.867 DeConz Hub: Send Command /api/13485B9E27/sensors/153 with None (0 in buffer) 2023-01-17 08:55:55.867 DeConz Hub: Making Request: http://127.0.0.1:8080/api/13485B9E27/sensors/153 with params None 2023-01-17 08:55:55.869 DeConz Hub: Request Return: {"config":{"filterlifetime":259200,"ledindication":true,"locked":false,"mode":"off","on":true,"reachable":true},"ep":1,"etag":"b179ede6da8ea670b8c95060e6ae9ba0","lastannounced":null,"lastseen":"2023-01-17T07:55Z","manufacturername":"IKEA of Sweden","modelid":"STARKVIND Air purifier","name":"PM2.5 Slaapkamer","state":{"deviceruntime":690,"filterruntime":690,"lastupdated":"2023-01-16T07:46:05.161","replacefilter":false,"speed":20},"swversion":"1.0.033","type":"ZHAAirPurifier","uniqueid":"2c:11:65:ff:fe:b0:88:39-01-fc7d"} 2023-01-17 08:55:55.869 DeConz Hub: Classic Data : {'config': {'filterlifetime': 259200, 'ledindication': True, 'locked': False, 'mode': 'off', 'on': True, 'reachable': True}, 'ep': 1, 'etag': 'b179ede6da8ea670b8c95060e6ae9ba0', 'lastannounced': None, 'lastseen': '2023-01-17T07:55Z', 'manufacturername': 'IKEA of Sweden', 'modelid': 'STARKVIND Air purifier', 'name': 'PM2.5 Slaapkamer', 'state': {'deviceruntime': 690, 'filterruntime': 690, 'lastupdated': '2023-01-16T07:46:05.161', 'replacefilter': False, 'speed': 20}, 'swversion': '1.0.033', 'type': 'ZHAAirPurifier', 'uniqueid': '2c:11:65:ff:fe:b0:88:39-01-fc7d'} 2023-01-17 08:55:55.869 DeConz Hub: ### Device > 153 Name:PM2.5 Slaapkamer Type:ZHAAirPurifier Details:{'deviceruntime': 690, 'filterruntime': 690, 'lastupdated': '2023-01-16T07:46:05.161', 'replacefilter': False, 'speed': 20} and {'filterlifetime': 259200, 'ledindication': True, 'locked': False, 'mode': 'off', 'on': True, 'reachable': True} 2023-01-17 08:55:55.869 DeConz Hub: onMessage called\ 2023-01-17 08:55:55.869 DeConz Hub: ### WebSocket Data : {'attr': {'id': '154', 'lastannounced': None, 'lastseen': '2023-01-17T07:55Z', 'manufacturername': 'IKEA of Sweden', 'modelid': 'STARKVIND Air purifier', 'name': 'PM2.5 Slaapkamer', 'swversion': '1.0.033', 'type': 'ZHAAirQuality', 'uniqueid': '2c:11:65:ff:fe:b0:88:39-02-fc7d'}, 'e': 'changed', 'id': '154', 'r': 'sensors', 't': 'event', 'uniqueid': '2c:11:65:ff:fe:b0:88:39-02-fc7d'} 2023-01-17 08:55:55.869 Status: DeConz Hub: Adding missing device: 153 Type:ZHAAirPurifier 2023-01-17 08:55:55.867 Error: DeConz Hub: Websocket error, unknown device > 153 (sensors) Asking for information 2023-01-17 08:55:56.019 DeConz Hub: onMessage called 2023-01-17 08:55:56.019 DeConz Hub: ### WebSocket Data : {'attr': {'id': '3', 'lastannounced': None, 'lastseen': '2023-01-17T07:55Z', 'manufacturername': 'Philips', 'modelid': 'ROM001', 'name': 'Knop Babykamer', 'swversion': '2.25.0_r30044', 'type': 'ZHASwitch', 'uniqueid': '00:17:88:01:06:54:ea:66-01-fc00'}, 'e': 'changed', 'id': '3', 'r': 'sensors', 't': 'event', 'uniqueid': '00:17:88:01:06:54:ea:66-01-fc00'} 2023-01-17 08:55:57.072 DeConz Hub: onHeartbeat called 2023-01-17 08:55:57.373 DeConz Hub: onCommand called for Unit 228: Parameter 'Set Level', Level: 10, Hue: 2023-01-17 08:55:57.373 DeConz Hub: Send Command /api/13485B9E27/sensors/153/config with {'mode': 'auto'} (0 in buffer) 2023-01-17 08:55:57.373 DeConz Hub: Making Request: http://127.0.0.1:8080/api/13485B9E27/sensors/153/config with params {'mode': 'auto'} 2023-01-17 08:55:57.377 DeConz Hub: Request Return: [{"success":{"/sensors/153/config/mode":"auto"}}] 2023-01-17 08:55:57.377 DeConz Hub: Classic Data : [{'success': {'/sensors/153/config/mode': 'auto'}}] 2023-01-17 08:55:57.377 DeConz Hub: onMessage called 2023-01-17 08:55:57.377 DeConz Hub: ### WebSocket Data : {'config': {'filterlifetime': 259200, 'ledindication': True, 'locked': False, 'mode': 'auto', 'on': True, 'reachable': True}, 'e': 'changed', 'id': '153', 'r': 'sensors', 't': 'event', 'uniqueid': '2c:11:65:ff:fe:b0:88:39-01-fc7d'} 2023-01-17 08:55:57.377 DeConz Hub: Send Command /api/13485B9E27/sensors/153 with None (0 in buffer) 2023-01-17 08:55:57.377 DeConz Hub: Making Request: http://127.0.0.1:8080/api/13485B9E27/sensors/153 with params None 2023-01-17 08:55:57.380 DeConz Hub: Request Return: {"config":{"filterlifetime":259200,"ledindication":true,"locked":false,"mode":"auto","on":true,"reachable":true},"ep":1,"etag":"5f285675e0bf8aa45b24e91f36341d73","lastannounced":null,"lastseen":"2023-01-17T07:55Z","manufacturername":"IKEA of Sweden","modelid":"STARKVIND Air purifier","name":"PM2.5 Slaapkamer","state":{"deviceruntime":690,"filterruntime":690,"lastupdated":"2023-01-16T07:46:05.161","replacefilter":false,"speed":20},"swversion":"1.0.033","type":"ZHAAirPurifier","uniqueid":"2c:11:65:ff:fe:b0:88:39-01-fc7d"} 2023-01-17 08:55:57.380 DeConz Hub: Classic Data : {'config': {'filterlifetime': 259200, 'ledindication': True, 'locked': False, 'mode': 'auto', 'on': True, 'reachable': True}, 'ep': 1, 'etag': '5f285675e0bf8aa45b24e91f36341d73', 'lastannounced': None, 'lastseen': '2023-01-17T07:55Z', 'manufacturername': 'IKEA of Sweden', 'modelid': 'STARKVIND Air purifier', 'name': 'PM2.5 Slaapkamer', 'state': {'deviceruntime': 690, 'filterruntime': 690, 'lastupdated': '2023-01-16T07:46:05.161', 'replacefilter': False, 'speed': 20}, 'swversion': '1.0.033', 'type': 'ZHAAirPurifier', 'uniqueid': '2c:11:65:ff:fe:b0:88:39-01-fc7d'} 2023-01-17 08:55:57.380 DeConz Hub: ### Device > 153 Name:PM2.5 Slaapkamer Type:ZHAAirPurifier Details:{'deviceruntime': 690, 'filterruntime': 690, 'lastupdated': '2023-01-16T07:46:05.161', 'replacefilter': False, 'speed': 20} and {'filterlifetime': 259200, 'ledindication': True, 'locked': False, 'mode': 'auto', 'on': True, 'reachable': True} 2023-01-17 08:55:57.342 Status: User: Admin (IP: 10.0.0.101) initiated a switch command (725/DeConz Hub - PM2.5 Slaapkamer/Set Level) 2023-01-17 08:55:57.380 Status: DeConz Hub: Adding missing device: 153 Type:ZHAAirPurifier 2023-01-17 08:55:57.377 Error: DeConz Hub: Websocket error, unknown device > 153 (sensors) Asking for information

DeCONZ ID 153 = ZHAAirPurifier (Fan and filter info) DeCONZ ID 154 = ZHAAirQuality (PM2.5 sensor) Domoticz ID 228 = Fan Switch Domoticz ID 229 = Group Switch

It's really weird this isn't working.. The request is on the correct entry, with an accepted value.

Only values S1 to S5 are still wrong I think. In the GUI, the accepted values are: Off, Low, Medium, High, On, Auto, Smart strkvnd

When using the Group switch also nothing happens but, the log is a lot shorter 2023-01-17 08:54:50.679 DeConz Hub: onCommand called for Unit 229: Parameter 'Set Level', Level: 10, Hue: 2023-01-17 08:54:50.677 Status: User: Admin (IP: 10.0.0.101) initiated a switch command (726/DeConz Hub - PM2.5 Slaapkamer/Set Level) 2023-01-17 08:54:50.679 Error: DeConz Hub: This device doesn't support action

You have a direct acces to the api in domoticz (to see or write values), on Domoticz/Custom/Deconz/Sensor.

Oh wow, learned something cool today :) Thanks, didn't knew that was possible.

Smanar commented 1 year ago

Oh wow, learned something cool today :) Thanks, didn't knew that was possible

Yeah and can too use that https://github.com/Smanar/Domoticz-deCONZ/wiki/Example-to-use-custom-widget-to-act-direclty-on-the-deconz-API

Some setting are used only 1 time by year, so I prefer don't use a widget just for that.

Edit: So I have found a problem The device was not added

2023-01-17 08:55:57.380 Status: DeConz Hub: Adding missing device: 153 Type:ZHAAirPurifier
2023-01-17 08:55:57.377 Error: DeConz Hub: Websocket error, unknown device > 153 (sensors) Asking for informatio

So I have made a complete rollback, so new code (with new problems) With it you need to have

And have checked code again, the API don't use same value in the GUI https://github.com/dresden-elektronik/deconz-rest-plugin/blob/12f7f3610c985c47efe6980a205672925d0c82ae/devices/ikea/starkvind_write_target_mode.js

Sorry again for all retries.

Edit: Ok so not possible for pm2.5 https://www.breeze-technologies.de/blog/air-pollution-how-to-convert-between-mgm3-%C2%B5gm3-ppm-ppb/

For this one need to use µg/m³ Bad because the widget is fine, can have more than 1 information on the same ...

arjannv commented 1 year ago

No problem :) Happy to help.

It added another selector switch, but it gives an error every few seconds: 2023-01-17 13:26:44.119 Error: DeConz Hub: Call to function 'onHeartbeat' failed, exception details: 2023-01-17 13:26:44.119 Error: DeConz Hub: Traceback (most recent call last): 2023-01-17 13:26:44.119 Error: DeConz Hub: File "/home/arjan/domoticz/plugins/Domoticz-deCONZ/plugin.py", line 1146, in onHeartbeat 2023-01-17 13:26:44.119 Error: DeConz Hub: _plugin.onHeartbeat() 2023-01-17 13:26:44.119 Error: DeConz Hub: File "/home/arjan/domoticz/plugins/Domoticz-deCONZ/plugin.py", line 500, in onHeartbeat 2023-01-17 13:26:44.119 Error: DeConz Hub: self.ManageInit() 2023-01-17 13:26:44.119 Error: DeConz Hub: File "/home/arjan/domoticz/plugins/Domoticz-deCONZ/plugin.py", line 558, in ManageInit 2023-01-17 13:26:44.119 Error: DeConz Hub: self.SendCommand("/api/" + Parameters["Mode2"] + "/" + self.INIT_STEP[0] + "/") 2023-01-17 13:26:44.119 Error: DeConz Hub: File "/home/arjan/domoticz/plugins/Domoticz-deCONZ/plugin.py", line 1039, in SendCommand 2023-01-17 13:26:44.119 Error: DeConz Hub: self.UpdateBuffer() 2023-01-17 13:26:44.119 Error: DeConz Hub: File "/home/arjan/domoticz/plugins/Domoticz-deCONZ/plugin.py", line 1080, in UpdateBuffer 2023-01-17 13:26:44.119 Error: DeConz Hub: self.NormalConnexion(_Data) 2023-01-17 13:26:44.119 Error: DeConz Hub: File "/home/arjan/domoticz/plugins/Domoticz-deCONZ/plugin.py", line 799, in NormalConnexion 2023-01-17 13:26:44.119 Error: DeConz Hub: self.InitDomoticzDB(i,_Data[i],self.INIT_STEP[0]) 2023-01-17 13:26:44.119 Error: DeConz Hub: File "/home/arjan/domoticz/plugins/Domoticz-deCONZ/plugin.py", line 735, in InitDomoticzDB 2023-01-17 13:26:44.119 Error: DeConz Hub: UpdateDevice(key, Type_device, kwarg, self.SpecialDeviceList) 2023-01-17 13:26:44.119 Error: DeConz Hub: File "/home/arjan/domoticz/plugins/Domoticz-deCONZ/plugin.py", line 1299, in UpdateDevice 2023-01-17 13:26:44.119 Error: DeConz Hub: UpdateDevice_Special(_id, _type, kwarg, d) 2023-01-17 13:26:44.119 Error: DeConz Hub: File "/home/arjan/domoticz/plugins/Domoticz-deCONZ/plugin.py", line 1286, in UpdateDevice_Special 2023-01-17 13:26:44.119 Error: DeConz Hub: UpdateDeviceProc(kwarg2,Unit2) 2023-01-17 13:26:44.119 Error: DeConz Hub: File "/home/arjan/domoticz/plugins/Domoticz-deCONZ/plugin.py", line 1317, in UpdateDeviceProc 2023-01-17 13:26:44.119 Error: DeConz Hub: if kwarg[a] != getattr(Devices[Unit], a ): 2023-01-17 13:26:44.119 Error: DeConz Hub: AttributeError: 'Domoticz.Device' object has no attribute 'speed'

Edit: It didn't recreate the PM2.5 sensor. Is that something you are still working on?

Smanar commented 1 year ago

Have corrected the error

Edit: It didn't recreate the PM2.5 sensor. Is that something you are still working on?

No sensor at all ? It's perhaps because this error have totally broked the code, the plugin haven't started yet according to your logs

The code seem fine for me

            elif Type == 'ZHAAirQuality':
                if 'pm2_5' in StateList:
                    self.CreateIfnotExist(IEEE,'ZHAAirPurifier',Name,1)
                else:
                    self.CreateIfnotExist(IEEE,'ZHAAirPurifier',Name)
    elif _Type == 'ZHAAirQuality':
        #kwarg['TypeName'] = 'Air Quality'
        kwarg['TypeName'] = 'Custom'
        if opt == 1:
            kwarg['Options'] = {"Custom": ("1;µg/m3")}
        else:
            kwarg['Options'] = {"Custom": ("1;ppb")}
arjannv commented 1 year ago

Great! Selector switch now works! Still no PM2.5 sensor. will re-add the device to check if it helps. Will report back :)

arjannv commented 1 year ago

Ok, removed all stuff and re-added the Starkvind to DeCONZ. It created a Fan selector switch and two sensors. See picture below. 1st is the PM2.5 level (in m/s???) and 2nd is another custom sensor with a value in m/s. strkvnd The first sensor works perfectly, only the units are in m/s. I really don't know which sensor the second one is. In the picture it shows a value of 20 m/s, but I can't find an attribute with a value of 20. image

The selector switch works (kind of). When I select a option "Auto, S1-S5", the Starkvind goes to that option (Auto or S1-S5). But the switch in Domoticz jumps always to S1. This is with all options except "Off".

Edit: Upon closer look, the second sensor value of 20 is the level value of the Fan selector switch (20 = Auto). When I change the Fan selector, the selector jumps to "S1" while the 2nd sensor goes to the corresponding level.

Another Edit: Checked a bit more. The second sensor seems to be the value of attribute 0x0007 2. In auto mode this varies based upon the PM2.5 level. So it is not directly the Fan Mode, but the Fan duty. Which is nice, but I think this should be in % not m/s. At maximum fan speed, 0x0007 gives a value of 50, so the 2 is perfect.

Smanar commented 1 year ago

Lol, seriously there is something magic on thoses custom sensors ....

So yes the "speed" is the attribute 0x0007 but I don't have found information about the "value", for me a speed is in m/s and its the value displayed in the API, raw value. The "speed" return can be different from the value you set in "mode" yes, so for me it's more usefull than the filterlifetime, and move more often. From here the value can reach 100 https://github.com/dresden-elektronik/deconz-rest-plugin/pull/6118#issue-1262201522

So new modifications :

You can just remove the pm2.5 sensor for this try, no change on others.

arjannv commented 1 year ago

Thanks for the modifications.

Yes, it is a very nice value to have, the speed. It would be nice to use it for automations, limiting the speed when the mode is on "auto" for instance. The other values are only used rarely I suspect.

Fan selector switch is working now! The mode now is the same in Domoticz and on the Starkvind. The PM2.5 sensor was recreated automatically with m/s. It was possible to change this manually to μg/m³.

Smanar commented 1 year ago

The PM2.5 sensor was recreated automatically with m/s

Edit: Have found the problem. I have set the good unity too in the widget file, but idk how domoticz will react with character "μ", if you have problem, edit the file widget.py at line 105

kwarg['Options'] = {"Custom": ("1;μg/m³")}

arjannv commented 1 year ago

Hmm, strange. The weird thing is that they are both added as a ZHAAirPurifier 2023-01-18 16:32:39.165 Status: DeConz Hub: ### Create Device 2c:11:65:ff:fe:b0:88:39-01-fc7d > Lucht Slaapkamer (ZHAAirPurifier) as Unit 229 2023-01-18 16:32:39.169 Status: DeConz Hub: ### Create Device 2c:11:65:ff:fe:b0:88:39-02-fc7d > Lucht Slaapkamer (ZHAAirPurifier) as Unit 230 So the end up both with m/s as unit.

Edit: It works now! Your last change fixed the problem. Now i've got two sensors, 1 with m/s and one with µg/m³!

Smanar commented 1 year ago

Ha ^^ finally :)