This Flask-based wrapper of the great homematicip-rest-api can be used to integrate with various other gateways that allow for a GraphQL access.
Note
This is a very first version. As of now, the model only supports TemperatureHumiditySensorDisplay and ShutterContact, as these are those sensors that I have in use right now. However this could be easily extended.
- Clone this repo
git clone https://github.com/martin-riedl/homematic-gqls
- Obtain authtoken from Homematic IP Cloud
- Follow the instructions from homematicip-rest-api to obtain an authtoken for your homematicIP cloud account (hereby a file config.ini is created).
- Copy the resulting file config.ini into the main directory of this repository.
- Install the requirements
pip3 install -r requirements --user
- Start the server
python3 server.py
GraphQL can serve over http via GET and POST requests.
A POST request using curl
curl -X POST localhost:8191/graphql -H "Content-Type: application/json" --data '{"query":"{shuttercontacts{windowState}}"}'
or using a filter on the label
curl -X POST localhost:8191/graphql -H "Content-Type: application/json" --data '{"query":"{shuttercontacts_filtered (label_filter : "mylabelorempty") {label windowState}}"}'
A GET request using curl
curl -X GET localhost:8191/graphql?query=%7Bshuttercontacts%7BwindowState%7D%7D
For further information see OpenHAB HTTP Binding.
A request via HTTP GET which refreshes each 60k ms may look as follows:
String windowstatus "WindowStatus [%s]" { http="<[http://myhost:8191/graphql?query=%%7Bshuttercontacts%%7BwindowState%%7D%%7D:8191:JSONPATH($.data.shuttercontacts[0].windowState)]" }
Building the image:
docker build --tag hmgqls .
Running the container (bound to localhost on the host):
docker run -p 8191:8191 -d --restart unless-stopped --name hmgqls hmgqls
And check in the browser to see the Playground UI.
Or query a specific device, e.g. http://localhost:8191/graphql?query={shuttercontacts{windowState}}