# node-red-contrib-mygekko

Connects to the Query-Api of the homeautomation system MyGEKKO.  
Allows to poll the Query-Api and generates a message on every status/data-change.  
Additionally the linked mygekko-systems can be controlled through the supported Query-Api-commands.  
Supports connection through MyGekko-Plus-Services and local connection.  
Direct support of [node-red-contrib-alexa-home](https://flows.nodered.org/node/node-red-contrib-alexa-home) nodes on mygekko-light-nodes and mygekko-blind-nodes.

## Installation
```bash
cd ~/.node-red
npm install node-red-contrib-mygekko
sudo service nodered restart
```

## How to use
  
  * Add the desired mygekko-node from the palette to your flow.  
  
    ![Node Config](http://dev.byteschreinerei.de/node-red/node-red-contrib-mygekko/img/node_config.png)  
    
  * Configure the used **Name** for the node  
      
    **Note:** If you want to use the **auto-itemid-assign-feature** (recommended), you have to use the same **Name** for the node as used in the MyGekko-System, in such case leave the field **ItemId** empty.  
    The server-node will then try to auto-assign the correct MyGekko-ItemId to the node.  
      
    You can also assign the **ItemId** directly, therefor enter the MyGekko-ItemId (like item18). In such case, the **Name** can be any value.  
  
    <details>
           <summary>Check auto-itemid-assign-feature</summary>
           <p>When you use **auto-itemid-assign-feature** the node will appear as **connected** after deploying:<br/>
           <br/>
           <img src="http://dev.byteschreinerei.de/node-red/node-red-contrib-mygekko/img/node_connected.png" alt="Node connected"/><br/>  
            When the server-node **could not auto assign** the correct itemid, perhaps because of using a false name, the node will throw a message:<br/>
            <br/>
            <img src="http://dev.byteschreinerei.de/node-red/node-red-contrib-mygekko/img/node_not_assigned.png" alt="Node not assigned"/></p>
    </details>

  
  * Assign a existing MyGekko-Server to the node or create a new one

    **Note:** You can set the **Active** flag in the server-config for polling the QueryApi.  
    If you just want to write back values to QueryApi, you can disable polling.  
  
    ![Server Config](http://dev.byteschreinerei.de/node-red/node-red-contrib-mygekko/img/server_config.png)  
  
## Overview supported features
  
**Detailed information for each individual node can be viewed in the info pane within the node-red-flow-editor.**  
  * All nodes with output
    * all nodes with an output generate a message with the properties of the linked mygekko-component on each change in its property-values.
    
  * LIGHT (mygekko_light)
    * Get/Set the current state (on/off)
    * Get/Set the current dimming-value
    * Get/Set the current light-color (24-bit-value)
    * Ability to direct connect a [node-red-contrib-alexa-home](https://flows.nodered.org/node/node-red-contrib-alexa-home) node on input
  
  * LOAD (mygekko_load)
    * Get/Set the current state (on, impulse on, off)
    
  * ACTION (mygekko_action)
    * Get/Set the current state (start, stop)
    
  * BLIND (mygekko_blind)
    * Get/Set the current state (hold_down, stop, up, ...)
    * Get/Set the current position
    * Get/Set the current angle (slate-rotation)
    * Ability to direct connect a [node-red-contrib-alexa-home](https://flows.nodered.org/node/node-red-contrib-alexa-home) node on input
      
  * ALARM (mygekko_alarm)
    * Get the current status from alarm-system
      
  * UNIVERSAL (mygekko_universal)
    * Get the complete JSON-Response for all components from QueryApi
      
  * PROFILE (mygekko_profile)
    * Get/Set the current profile (Away, at Home)
      
  * VENT (mygekko_vent)
    * Get the current values from ventilation (level, mode, bypass, temperatures, co2, voc, humidity)
    * Set the level for ventilation
  
  * METEO (mygekko_meteo)
    * Get the current values from the Meteo-Component from MyGekko if configured (twilight, temperature-outside)
  
## Depencies
This package has no extra requirements, it doesn't add any dependencies, so it can be used in every standard-node-red-installation.  

## Sample Node-Red-Flow
Here´s a sample node-red-flow to start working with the nodes.  
  
![Sample 1 Overview](http://dev.byteschreinerei.de/node-red/node-red-contrib-mygekko/img/sample_1.png)  

```json
[{"id":"66f2024a.cf85cc","type":"inject","z":"1e0aa667.3f381a","name":"Lampe ein","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":123,"wires":[["705800d7.63832"]]},{"id":"a4d2a866.7de3f8","type":"debug","z":"1e0aa667.3f381a","name":"Debug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1030,"y":340,"wires":[]},{"id":"21a0abb7.44c2e4","type":"mygekko_light","z":"1e0aa667.3f381a","name":"Wohnen Deckenlicht","itemid":"","server":"14744af.47b48b5","x":540,"y":143,"wires":[["a4d2a866.7de3f8"]]},{"id":"705800d7.63832","type":"change","z":"1e0aa667.3f381a","name":"Set","rules":[{"t":"set","p":"state","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":330,"y":123,"wires":[["21a0abb7.44c2e4"]]},{"id":"c2816116.d854f","type":"change","z":"1e0aa667.3f381a","name":"Set","rules":[{"t":"set","p":"state","pt":"msg","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":330,"y":163,"wires":[["21a0abb7.44c2e4"]]},{"id":"e95a157c.231478","type":"inject","z":"1e0aa667.3f381a","name":"Lampe aus","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":163,"wires":[["c2816116.d854f"]]},{"id":"7e1cd863.577418","type":"mygekko_alarm","z":"1e0aa667.3f381a","name":"Alarm","server":"14744af.47b48b5","x":590,"y":60,"wires":[["a4d2a866.7de3f8"]]},{"id":"e0679067.b88cb","type":"mygekko_profile","z":"1e0aa667.3f381a","name":"Profil","server":"14744af.47b48b5","x":590,"y":250,"wires":[["a4d2a866.7de3f8"]]},{"id":"f3db2837.e41f88","type":"inject","z":"1e0aa667.3f381a","name":"Profil \"zu Hause\"","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":230,"wires":[["d0a6e0f9.22038"]]},{"id":"d0a6e0f9.22038","type":"change","z":"1e0aa667.3f381a","name":"Set","rules":[{"t":"set","p":"profileid","pt":"msg","to":"1","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":330,"y":230,"wires":[["e0679067.b88cb"]]},{"id":"77e3c49.004bd3c","type":"change","z":"1e0aa667.3f381a","name":"Set","rules":[{"t":"set","p":"profileid","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":330,"y":270,"wires":[["e0679067.b88cb"]]},{"id":"d6617b6.6fdbb88","type":"inject","z":"1e0aa667.3f381a","name":"Profil \"ausser Haus\"","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":270,"wires":[["77e3c49.004bd3c"]]},{"id":"32c2c382.755bec","type":"mygekko_load","z":"1e0aa667.3f381a","name":"TV","itemid":"","server":"14744af.47b48b5","x":590,"y":355,"wires":[["a4d2a866.7de3f8"]]},{"id":"95f39574.c0c2d8","type":"inject","z":"1e0aa667.3f381a","name":"TV ein","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":120,"y":335,"wires":[["47fbc6cc.e31b48"]]},{"id":"47fbc6cc.e31b48","type":"change","z":"1e0aa667.3f381a","name":"Set","rules":[{"t":"set","p":"payload","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":330,"y":335,"wires":[["32c2c382.755bec"]]},{"id":"149b9a7.81bc566","type":"change","z":"1e0aa667.3f381a","name":"Set","rules":[{"t":"set","p":"payload","pt":"msg","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":330,"y":375,"wires":[["32c2c382.755bec"]]},{"id":"fe7b2f71.946b5","type":"inject","z":"1e0aa667.3f381a","name":"TV aus","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":120,"y":375,"wires":[["149b9a7.81bc566"]]},{"id":"19728f63.8fc3a1","type":"mygekko_action","z":"1e0aa667.3f381a","name":"Alle Lichter aus","itemid":"","server":"14744af.47b48b5","x":560,"y":454,"wires":[["a4d2a866.7de3f8"]]},{"id":"2d9110ab.b4995","type":"inject","z":"1e0aa667.3f381a","name":"start Aktion","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":434,"wires":[["d7ee2a11.bb8bf8"]]},{"id":"d7ee2a11.bb8bf8","type":"change","z":"1e0aa667.3f381a","name":"Set","rules":[{"t":"set","p":"payload","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":330,"y":434,"wires":[["19728f63.8fc3a1"]]},{"id":"b5df069f.8aa348","type":"change","z":"1e0aa667.3f381a","name":"Set","rules":[{"t":"set","p":"payload","pt":"msg","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":330,"y":474,"wires":[["19728f63.8fc3a1"]]},{"id":"afd72f9c.1c8d1","type":"inject","z":"1e0aa667.3f381a","name":"stop Aktion","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":474,"wires":[["b5df069f.8aa348"]]},{"id":"e7cf9db3.26e7e","type":"mygekko_blind","z":"1e0aa667.3f381a","name":"Küche Rollo","itemid":"","server":"14744af.47b48b5","x":580,"y":619,"wires":[["a4d2a866.7de3f8"]]},{"id":"293c8cce.32aaf4","type":"inject","z":"1e0aa667.3f381a","name":"Position 100%","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":539,"wires":[["e4edd5b3.ec09e8"]]},{"id":"e4edd5b3.ec09e8","type":"change","z":"1e0aa667.3f381a","name":"Set","rules":[{"t":"set","p":"payload","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":330,"y":539,"wires":[["e7cf9db3.26e7e"]]},{"id":"b643a6f7.6eef08","type":"change","z":"1e0aa667.3f381a","name":"Set","rules":[{"t":"set","p":"payload","pt":"msg","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":330,"y":619,"wires":[["e7cf9db3.26e7e"]]},{"id":"b525c3cf.620e2","type":"inject","z":"1e0aa667.3f381a","name":"Position 0%","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":619,"wires":[["b643a6f7.6eef08"]]},{"id":"cf7a94f7.f4abf8","type":"change","z":"1e0aa667.3f381a","name":"Set","rules":[{"t":"set","p":"position","pt":"msg","to":"50","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":330,"y":579,"wires":[["e7cf9db3.26e7e"]]},{"id":"a0cf8f3a.41531","type":"inject","z":"1e0aa667.3f381a","name":"Position 50%","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":579,"wires":[["cf7a94f7.f4abf8"]]},{"id":"3fcfae98.e21232","type":"change","z":"1e0aa667.3f381a","name":"Set","rules":[{"t":"delete","p":"payload","pt":"msg"},{"t":"set","p":"angle","pt":"msg","to":"25","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":330,"y":659,"wires":[["e7cf9db3.26e7e"]]},{"id":"68a292a2.fd4afc","type":"inject","z":"1e0aa667.3f381a","name":"Winkel 25%","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":659,"wires":[["3fcfae98.e21232"]]},{"id":"c1c4169c.dd0b58","type":"change","z":"1e0aa667.3f381a","name":"Set","rules":[{"t":"delete","p":"payload","pt":"msg"},{"t":"set","p":"stateid","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":330,"y":699,"wires":[["e7cf9db3.26e7e"]]},{"id":"119a6da.9c74392","type":"inject","z":"1e0aa667.3f381a","name":"stop","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":120,"y":699,"wires":[["c1c4169c.dd0b58"]]},{"id":"bb921b92.c7f878","type":"mygekko_universal","z":"1e0aa667.3f381a","name":"","server":"14744af.47b48b5","x":970,"y":590,"wires":[["a4d2a866.7de3f8"]]},{"id":"10a6ece8.f2fb83","type":"mygekko_vent","z":"1e0aa667.3f381a","name":"Erdgeschoss","itemid":"","server":"14744af.47b48b5","x":580,"y":780,"wires":[["a4d2a866.7de3f8"]]},{"id":"66ecb67b.8f0128","type":"inject","z":"1e0aa667.3f381a","name":"Lueftung aus","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":770,"wires":[["57706971.0ceba8"]]},{"id":"57706971.0ceba8","type":"change","z":"1e0aa667.3f381a","name":"Set","rules":[{"t":"set","p":"level","pt":"msg","to":"-1","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":330,"y":770,"wires":[["10a6ece8.f2fb83"]]},{"id":"15ce6649.8f74ca","type":"change","z":"1e0aa667.3f381a","name":"Set","rules":[{"t":"set","p":"level","pt":"msg","to":"2","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":330,"y":810,"wires":[["10a6ece8.f2fb83"]]},{"id":"8aad7590.9c0a68","type":"inject","z":"1e0aa667.3f381a","name":"Lueftung Stufe 2","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":810,"wires":[["15ce6649.8f74ca"]]},{"id":"14744af.47b48b5","type":"mygekko_server","z":"","active":true,"api":"local","host":"192.168.178.111","interval":"5"}]
```
  
## Changelog

* 1.0.6  
    initial repository-release  

* 1.0.7  
    modified "readme"  

* 1.0.8  
    added Version history , added new node "mygekko_vent" for reading and setting values from vents  

* 1.0.9/.10  
    added new node "mygekko_meteo" for reading values from the Meteo-component (currently twilight, temperature-outside)  

* 1.0.11  
    improvements in rounding float-values to 1 decimal place for fewer messages  

* 1.0.12  
    enhanced description for vent-outputs in info-pane in node-red-flow-editor  
  
* 1.0.13/14/15/16/17  
    reworked "readme"  
  
* 1.0.18  
    Added direct input-support for [node-red-contrib-alexa-home](https://flows.nodered.org/node/node-red-contrib-alexa-home) in light-node. Nodes can be wired directly.

* 1.0.19
    fixed bug in light-node, alexa-home compability color values

* 1.0.20
    fixed "reference-error" in light-node

* 1.0.21
    Added direct input-support for [node-red-contrib-alexa-home](https://flows.nodered.org/node/node-red-contrib-alexa-home) in blind-node. Nodes can be wired directly.