tim-hellhake / shelly-adapter

Mozilla Public License 2.0
2 stars 6 forks source link

Feature Request: Add Roller Shutter Mode (Shelly 2.5) #3

Closed rmeissn closed 4 years ago

rmeissn commented 4 years ago

I'm having a Shelly 2.5 in roller shutter mode in my network. The device is discovered by your addon, but it isn't recognized as a roller shutter. It would be great if you would add this device/mode to your addon, so it is auto-discovered correctly. Currently I'm using the http addon to send requests to the device (open/close).

E.g. the REST API is described here: https://shelly-api-docs.shelly.cloud/#shelly2-5-roller-index

I'm also happy to help and test, but I've just started today to play with the iot gateway as an end user.

krishnanarun commented 4 years ago

I have the same issue with a Shelly 2 as well. Gets recoginzed automatically through this Adapter but adds the device wrongly and with a very restrictive property set. I have tried searching around how to correct it to no avail but the closest I have got is to find the code that takes care of this in the following github repo https://github.com/marcogazzola/shelly-python. Would be great if you could help add this feature to your adapter as well. I lack programming experience but if you give directions, I can help run and debug setups/commands. Another thing to note is that both Shelly 2 and 2.5 in relay mode have 2 switches and the roller mode operates as one switch which can be identified by the mode and num_outputs properties in the status and settings API call. If you want to see the same from a online device, I can share the same as required. Thanks a lot in advance.

tim-hellhake commented 4 years ago

I'm currently working on replacing the library I'm using. This will allow me to add new features a lot faster. I would be glad if you could test the roller support for me.

krishnanarun commented 4 years ago

I would gladly provide support here as needed. I have 2 Shelly switches set up, one in Relay mode and the other in Roller mode so can surely help out here. But as I said, not a very good programmer but if you could provide directions, I can run any tests and circle back with feedback. Thanks.

tim-hellhake commented 4 years ago

I decided to keep the library as most of the missing parts were added by now. The addon should now detect if the shelly is in roller shutter mode and expose open, stop and close actions. I also added a property for the internal temperature. Maybe this is also interesting for you two.

tim-hellhake commented 4 years ago

The new update with the feature should be available as soon as the PR is merged. I am curious about your feedback.

krishnanarun commented 4 years ago

Hi Tim, I manuallz installed and updated the code to version 3 and ran the code. I am getting the following error on enabling the adapter: 2020-03-21 22:37:40.621 INFO : Loading add-on: shelly-adapter 2020-03-21 22:37:42.098 INFO : shelly-adapter: Opening database: /home/pi/.mozilla-iot/config/db.sqlite3 2020-03-21 22:37:43.236 INFO : shelly-adapter: Loading add-on shelly-adapter from /home/pi/.mozilla-iot/addons/shelly-adapter 2020-03-21 22:37:43.242 ERROR : shelly-adapter: { Error: Cannot find module '/home/pi/.mozilla-iot/addons/shelly-adapter' 2020-03-21 22:37:43.244 ERROR : shelly-adapter: at Function.Module._resolveFilename (module.js:548:15) 2020-03-21 22:37:43.246 ERROR : shelly-adapter: at Function.Module._load (module.js:475:25) 2020-03-21 22:37:43.247 ERROR : shelly-adapter: at Module.require (module.js:597:17) 2020-03-21 22:37:43.248 ERROR : shelly-adapter: at require (internal/module.js:11:18) 2020-03-21 22:37:43.250 ERROR : shelly-adapter: at pluginClient.register.catch.then (/home/pi/mozilla-iot/gateway/src/addon-loader.js:71:29) 2020-03-21 22:37:43.251 ERROR : shelly-adapter: at 2020-03-21 22:37:43.252 ERROR : shelly-adapter: at process._tickCallback (internal/process/next_tick.js:189:7) code: 'MODULE_NOT_FOUND' }

Any help in identifying the problem. Seems like it is not able to find a file module.js

tim-hellhake commented 4 years ago

Did you run npm run build before? This transpiles .ts files in src to .js files. Otherwise, the gateway can't load the module.

krishnanarun commented 4 years ago

From what I see, shouldn't there be an OpenProperty definition for the roller mode? I see only Switch Property, Temperature Property and Brightness Property. Also, Shelly-adapter.ts handles Shelly Dimmer and Rely but now there is a Roller mode as well which may be needed to be handled in the case statement for handleDeviceAdded. I may have missed something else but here is what I found for now. Thanks a lot for the really quick work that you provided and hope I was able to help.

PS: I did a npm install

tim-hellhake commented 4 years ago

I see only Switch Property, Temperature Property and Brightness Property.

Do you mean in the code or in the gateway?

tim-hellhake commented 4 years ago

From what I see, shouldn't there be an OpenProperty definition for the roller mode?

I'm using actions for this because open is a command rather than a state. They are registered here: https://github.com/tim-hellhake/shelly-adapter/blob/afe532d7e89123350aebe3d95ecf899770a1c94c/src/shelly-device.ts#L81

krishnanarun commented 4 years ago

Hey Tim, that solved the problem. The issue was that I only ran npm install instead of npm run build as you suggested. Now the devices are both recognized and working. Here is a small log file of the same. You do see some messages regarding missing property values for both relay and roller mode but the generic concept is working overall. Thanks a bunch.

2020-03-21 22:54:02.254 INFO : Loading add-on: shelly-adapter 2020-03-21 22:54:03.546 INFO : shelly-adapter: Opening database: /home/pi/.mozilla-iot/config/db.sqlite3 2020-03-21 22:54:04.666 INFO : shelly-adapter: Loading add-on shelly-adapter from /home/pi/.mozilla-iot/addons/shelly-adapter 2020-03-21 22:54:05.256 INFO : shelly-adapter: Discovered new Shelly2 with id 32BC85 2020-03-21 22:54:05.259 INFO : shelly-adapter: Configuring roller mode 2020-03-21 22:54:05.265 INFO : shelly-adapter: Discovered new Shelly2 with id 5B2799 2020-03-21 22:54:05.268 INFO : shelly-adapter: Configuring relay mode 2020-03-21 22:54:19.179 INFO : Opened a new things socket 2020-03-21 22:54:19.196 INFO : About to call startPairing on ThingURLAdapter 2020-03-21 22:54:19.198 INFO : About to call startPairing on ZigbeeAdapter 2020-03-21 22:54:19.200 INFO : About to call startPairing on ShellyAdapter 2020-03-21 22:54:19.236 INFO : shelly-adapter: Adapter: ShellyAdapter id ShellyAdapter pairing started 2020-03-21 22:54:19.238 INFO : zigbee-adapter: Pairing mode started, timeout = 60 2020-03-21 22:54:36.360 INFO : Successfully created new thing Shelly2 (32BC85) 2020-03-21 22:54:37.503 INFO : Successfully created new thing Shelly2 (5B2799) 2020-03-21 22:54:38.790 ERROR : Thing was not added 2020-03-21 22:54:38.793 ERROR : addNewThing cancelled 2020-03-21 22:54:38.809 INFO : zigbee-adapter: Cancelling pairing mode 2020-03-21 22:54:38.814 INFO : shelly-adapter: Adapter: ShellyAdapter id ShellyAdapter pairing cancelled 2020-03-21 22:54:38.816 INFO : thing-url-adapter: Adapter: ThingURLAdapter id thing-url-adapter pairing cancelled 2020-03-21 22:54:57.521 INFO : DeviceProxy: requestAction: open for: 32BC85 2020-03-21 22:54:57.530 INFO : shelly-adapter: Executing action open 2020-03-21 22:54:57.799 INFO : shelly-adapter: relay1 changed from false to true 2020-03-21 22:54:57.801 INFO : shelly-adapter: powerMeter0 changed from 0 to 1.0125 2020-03-21 22:54:57.803 INFO : shelly-adapter: rollerState changed from stop to close 2020-03-21 22:54:57.805 ERROR : shelly-adapter: No property for relay1 found 2020-03-21 22:54:57.807 ERROR : shelly-adapter: No property for powerMeter0 found 2020-03-21 22:54:57.808 ERROR : shelly-adapter: No property for rollerState found 2020-03-21 22:54:57.974 INFO : shelly-adapter: powerMeter0 changed from 1.0125 to 4.8125 2020-03-21 22:54:57.976 ERROR : shelly-adapter: No property for powerMeter0 found 2020-03-21 22:54:58.053 INFO : shelly-adapter: powerMeter0 changed from 4.8125 to 0 2020-03-21 22:54:58.055 ERROR : shelly-adapter: No property for powerMeter0 found 2020-03-21 22:54:58.292 INFO : shelly-adapter: powerMeter0 changed from 0 to 2.2125 2020-03-21 22:54:58.294 ERROR : shelly-adapter: No property for powerMeter0 found 2020-03-21 22:54:58.373 INFO : shelly-adapter: powerMeter0 changed from 2.2125 to 87.400002 2020-03-21 22:54:58.375 ERROR : shelly-adapter: No property for powerMeter0 found 2020-03-21 22:55:01.911 INFO : DeviceProxy: requestAction: stop for: 32BC85 2020-03-21 22:55:01.916 INFO : shelly-adapter: Executing action stop 2020-03-21 22:55:01.944 INFO : shelly-adapter: relay1 changed from true to false 2020-03-21 22:55:01.946 INFO : shelly-adapter: rollerPosition changed from 0 to 13 2020-03-21 22:55:01.947 INFO : shelly-adapter: powerMeter0 changed from 87.400002 to 83.550003 2020-03-21 22:55:01.949 INFO : shelly-adapter: rollerState changed from close to stop 2020-03-21 22:55:01.950 ERROR : shelly-adapter: No property for relay1 found 2020-03-21 22:55:01.952 ERROR : shelly-adapter: No property for rollerPosition found 2020-03-21 22:55:01.953 ERROR : shelly-adapter: No property for powerMeter0 found 2020-03-21 22:55:01.954 ERROR : shelly-adapter: No property for rollerState found 2020-03-21 22:55:03.641 INFO : DeviceProxy: requestAction: close for: 32BC85 2020-03-21 22:55:03.646 INFO : shelly-adapter: Executing action close 2020-03-21 22:55:03.871 INFO : shelly-adapter: relay0 changed from false to true 2020-03-21 22:55:03.873 INFO : shelly-adapter: powerMeter0 changed from 83.550003 to 0 2020-03-21 22:55:03.875 INFO : shelly-adapter: rollerState changed from stop to open 2020-03-21 22:55:03.876 ERROR : shelly-adapter: No property for relay0 found 2020-03-21 22:55:03.878 ERROR : shelly-adapter: No property for powerMeter0 found 2020-03-21 22:55:03.879 ERROR : shelly-adapter: No property for rollerState found 2020-03-21 22:55:03.968 INFO : shelly-adapter: powerMeter0 changed from 0 to 1.00625 2020-03-21 22:55:03.970 ERROR : shelly-adapter: No property for powerMeter0 found 2020-03-21 22:55:04.053 INFO : shelly-adapter: powerMeter0 changed from 1.00625 to 5.9125 2020-03-21 22:55:04.054 ERROR : shelly-adapter: No property for powerMeter0 found 2020-03-21 22:55:04.128 INFO : shelly-adapter: powerMeter0 changed from 5.9125 to 0 2020-03-21 22:55:04.130 ERROR : shelly-adapter: No property for powerMeter0 found 2020-03-21 22:55:04.368 INFO : shelly-adapter: powerMeter0 changed from 0 to 3.66875 2020-03-21 22:55:04.370 ERROR : shelly-adapter: No property for powerMeter0 found 2020-03-21 22:55:04.448 INFO : shelly-adapter: powerMeter0 changed from 3.66875 to 97.981247 2020-03-21 22:55:04.450 ERROR : shelly-adapter: No property for powerMeter0 found 2020-03-21 22:55:08.127 INFO : shelly-adapter: powerMeter0 changed from 97.981247 to 65.643753 2020-03-21 22:55:08.129 ERROR : shelly-adapter: No property for powerMeter0 found 2020-03-21 22:55:08.284 INFO : shelly-adapter: relay0 changed from true to false 2020-03-21 22:55:08.286 INFO : shelly-adapter: rollerPosition changed from 13 to 0 2020-03-21 22:55:08.287 INFO : shelly-adapter: powerMeter0 changed from 65.643753 to 0 2020-03-21 22:55:08.289 INFO : shelly-adapter: rollerState changed from open to stop 2020-03-21 22:55:08.290 ERROR : shelly-adapter: No property for relay0 found 2020-03-21 22:55:08.292 ERROR : shelly-adapter: No property for rollerPosition found 2020-03-21 22:55:08.293 ERROR : shelly-adapter: No property for powerMeter0 found 2020-03-21 22:55:08.294 ERROR : shelly-adapter: No property for rollerState found 2020-03-21 22:55:57.708 ERROR : TypeError: Cannot read property 'indexOf' of undefined at app.use (/home/pi/mozilla-iot/gateway/build/webpack:/src/app.js:258:1) at Layer.handle [as handle_request] (/home/pi/mozilla-iot/gateway/node_modules/express/lib/router/layer.js:95:5) at trim_prefix (/home/pi/mozilla-iot/gateway/node_modules/express/lib/router/index.js:317:13) at /home/pi/mozilla-iot/gateway/node_modules/express/lib/router/index.js:284:7 at Function.process_params (/home/pi/mozilla-iot/gateway/node_modules/express/lib/router/index.js:335:12) at next (/home/pi/mozilla-iot/gateway/node_modules/express/lib/router/index.js:275:10) at expressInit (/home/pi/mozilla-iot/gateway/node_modules/express/lib/middleware/init.js:40:5) at Layer.handle [as handle_request] (/home/pi/mozilla-iot/gateway/node_modules/express/lib/router/layer.js:95:5) at trim_prefix (/home/pi/mozilla-iot/gateway/node_modules/express/lib/router/index.js:317:13) at /home/pi/mozilla-iot/gateway/node_modules/express/lib/router/index.js:284:7 at Function.process_params (/home/pi/mozilla-iot/gateway/node_modules/express/lib/router/index.js:335:12) at next (/home/pi/mozilla-iot/gateway/node_modules/express/lib/router/index.js:275:10) at query (/home/pi/mozilla-iot/gateway/node_modules/express/lib/middleware/query.js:45:5) at Layer.handle [as handle_request] (/home/pi/mozilla-iot/gateway/node_modules/express/lib/router/layer.js:95:5) at trim_prefix (/home/pi/mozilla-iot/gateway/node_modules/express/lib/router/index.js:317:13) at /home/pi/mozilla-iot/gateway/node_modules/express/lib/router/index.js:284:7 2020-03-21 22:56:06.694 INFO : shelly-adapter: setCachedValueAndNotify for property relay0 from undefined to true for 5B2799 2020-03-21 22:56:06.720 INFO : shelly-adapter: relay0 changed from false to true 2020-03-21 22:56:06.779 INFO : shelly-adapter: powerMeter0 changed from 0 to 1.11875 2020-03-21 22:56:06.781 ERROR : shelly-adapter: No property for powerMeter0 found 2020-03-21 22:56:06.858 INFO : shelly-adapter: powerMeter0 changed from 1.11875 to 0 2020-03-21 22:56:06.860 ERROR : shelly-adapter: No property for powerMeter0 found 2020-03-21 22:56:06.939 INFO : shelly-adapter: powerMeter0 changed from 0 to 1.5 2020-03-21 22:56:06.941 ERROR : shelly-adapter: No property for powerMeter0 found 2020-03-21 22:56:07.018 INFO : shelly-adapter: powerMeter0 changed from 1.5 to 0 2020-03-21 22:56:07.020 ERROR : shelly-adapter: No property for powerMeter0 found 2020-03-21 22:56:07.098 INFO : shelly-adapter: powerMeter0 changed from 0 to 3.975 2020-03-21 22:56:07.100 ERROR : shelly-adapter: No property for powerMeter0 found 2020-03-21 22:56:07.178 INFO : shelly-adapter: powerMeter0 changed from 3.975 to 8.7625 2020-03-21 22:56:07.183 ERROR : shelly-adapter: No property for powerMeter0 found 2020-03-21 22:56:09.366 INFO : shelly-adapter: setCachedValueAndNotify for property relay0 from true to false for 5B2799 2020-03-21 22:56:09.394 INFO : shelly-adapter: relay0 changed from true to false 2020-03-21 22:56:09.396 INFO : shelly-adapter: powerMeter0 changed from 8.7625 to 0 2020-03-21 22:56:09.398 ERROR : shelly-adapter: No property for powerMeter0 found

krishnanarun commented 4 years ago

PS: I did a npm install

You need to run npm install and npm run build.

All good. Working perfectly now. I will need to update a bit to add position action and some other properties enabled but overall it works (last log above). Thanks a bunch. If you need to test any other features on this, please let me know and I can run it. Quite late now so rest for tomorrow. Thanks.

tim-hellhake commented 4 years ago

You do see some messages regarding missing property values for both relay and roller mode but the generic concept is working overall

I'm no longer using the relay0 property in roller shutter mode. That's why it looks like its missing now. Support for the power metric (powerMeter) is already on my todo list.

I'm currently experimenting with the roller mode property. There is support for locks in the gateway. It would look like this:

image

I'm not sure if this is helpful. One problem is I can't really tell if the shutter is closed or not. I only know your last command.

tim-hellhake commented 4 years ago

@rmeissn @CharlBest Did you have a chance to test it?

tim-hellhake commented 4 years ago

I'm closing this now. If you have any issues please open a new PR.