WebThingsIO / zigbee-adapter

Zigbee adapter add-on for WebThings Gateway
Mozilla Public License 2.0
46 stars 29 forks source link

Intercepting adapter's data #163

Closed Lukasz994 closed 4 years ago

Lukasz994 commented 5 years ago

Hi all, I am quite new to the project and therefore I could be missing something. I am managing several smart plugs through this adapter, yet I feel like there is room for some automation and I'd like to script up few steps of my daily routine. There are really 2 things I'd like to achieve: 1. Intercept data coming from adapter I'd like to be able to save output of adapter to SQLite that I could use for data analysis. Would you know whether there is a way for me to get that? or Where in code could I add custom code to redirect data to custom data store? I am aware that this may not be the best practice but I need a quick workaround. 2. Change adapter state programmatically How can one change adapter state? Where is the On/Off property actually stored? I am aware that 'Rules' allows for custom logic but that too simplistic for me, I need get my own code to access that adapter state. I read code of the adapter but cannot make sense of it. Could you point me in the right direction?

dhylands commented 5 years ago

This isn't specific to any one adapter.

The gateway has a rest API that can be used to query/modify the state of a thing, and you can use websockets to be notified when a thing changes state (this is what the gateway UI uses).

The https://github.com/mozilla-iot/curl-examples repository has some bash shell scripts which use curl to do exactly the above (minus the websocket portion).

This blog post: http://www.twobraids.com/2018/10/things-gateway-running-web-things-api.html shows how you might use the REST API to control things using python, and basically allows "rules" to be written in python.