Hi Folks,
because the current “pimatic-echo” plugins only supports on/off i search the internet for some better solutions.
Here it is, quick and dirty as always
So only for advanced pimatic users.
Maybe someone can build a native plugin based on this idea.
Path:
alexa -> node-red bridge -> node-red -> pimatic
Requirments:
- node-red (standalone or pimatic-nodered)
- read doc at https://alexa-node-red.bm.hardill.me.uk
- node-red-contrib-alexa-home-skill
- bridge account at https://alexa-node-red.bm.hardill.me.uk/
- alexa
- alexa node-red skill activated at the alexa skills
Currently supported:
- on / off
- +% & -%
- set to x%
- maybe get temperature and get state
Step-by-Step:
- get an account at https://alexa-node-red.bm.hardill.me.uk/
- add some devices with on/off/%/+%/-% at the “bridge”
- open node-red (standalone http://pimatic:1880; pimatic-nodered htttp://pimatic:8000/red)
- add the “node-red-contrib-alexa-home-skill” plugin under “Manage palette”
- add a “alexa home” device and build a workflow to trigger a pimatic device/button/variable (examples at the end post end)
- say “alexa desk brighter”
Using standalone node-red:
worked like a charm, no problems
Using pimatic-nodered:
could not install the “node-red-contrib-alexa-home-skill” via the node-red frontend.
Had to go to:
/home/pi/pimatic-app/node_modules/pimatic-node-red/node_modules/
and execute the npm command manual:
npm install node-red-contrib-alexa-home-skill
will be deleted with pimatic-nodered update
Further Information:
you can trigger nearly every device in pimatic.
Best way to understand how this is done, is the API definition at:
https://pimatic.org/api/actions/
and get a overview of you own devices (and actions) here:
http://pimatic/api/devices
Variables:
http://rasp/api/variables
Some german examples for alexa:
alexa küche heller -> 25% heller
alexa küche dunkler -> 25 % dunkler
alexa küche 10% -> light to 10%
alexa dimme küche auf 10% -> light to 10%
alexe küche an -> switches küche on
alexa küche aus -> switches küche off
alexa verstärker hoch -> triggers button vol_up
alexa verstärker runter -> trigger button vol_down
alexa verstärker an/aus -> clear?
Thats it
Example:
Here is an example you can copy right into node-red via the import button. its based on the pimatic-tradfri.
You have to add authentication to the http request “nodes”. if you want, you can add a debug to those “nodes”.
I currently save the pimatic device in “msg.device” and the action from alexa is saved in "msg.command"
The curent brightness for calculating the desired brightness is saved in “msg.brightnessChange” and “msg.brightness”
its also possible to use the given name from alexa in "msg.name"
but this is not always your deviceID in pimatic
[{"id":"e652390.52e5ac8","type":"switch","z":"d7cf668a.1dd428","name":"pimatic action","property":"command","propertyType":"msg","rules":[{"t":"eq","v":"TurnOnRequest","vt":"str"},{"t":"eq","v":"TurnOffRequest","vt":"str"},{"t":"eq","v":"SetPercentageRequest","vt":"str"},{"t":"eq","v":"DecrementPercentageRequest","vt":"str"},{"t":"eq","v":"IncrementPercentageRequest","vt":"str"}],"checkall":"false","outputs":5,"x":946.6666412353516,"y":521.6666488647461,"wires":[["61ddebf2.06c604"],["6f71be33.06fa1"],["f8ea8843.926848"],["2d77ef88.798df"],["2d77ef88.798df"]]},{"id":"f8ea8843.926848","type":"function","z":"d7cf668a.1dd428","name":"add brightness to msg","func":"msg.brightness = msg.payload\nreturn msg;","outputs":1,"noerr":0,"x":1244,"y":594,"wires":[["16c30fec.ff06a"]]},{"id":"2d77ef88.798df","type":"function","z":"d7cf668a.1dd428","name":"add brightnessChange to msg","func":"msg.brightnessChange = msg.payload\nreturn msg;","outputs":1,"noerr":0,"x":1280,"y":655,"wires":[["1feb7971.3cf497"]]},{"id":"d03767cb.8aff78","type":"alexa-home","z":"d7cf668a.1dd428","conf":"1dde58d1.d01427","device":"2842","acknoledge":true,"name":"Küche","topic":"","x":474.99999237060547,"y":518.3333778381348,"wires":[["855e288a.929af8"]]},{"id":"1feb7971.3cf497","type":"http request","z":"d7cf668a.1dd428","name":"","method":"GET","ret":"obj","url":"http://rasp/api/variables/{{device}}.dimlevel","tls":"","x":1540,"y":655,"wires":[["af11551c.995418"]]},{"id":"855e288a.929af8","type":"change","z":"d7cf668a.1dd428","name":"Kueche","rules":[{"t":"set","p":"device","pt":"msg","to":"tradfri_65538","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":710,"y":515,"wires":[["e652390.52e5ac8"]]},{"id":"eca55fc3.8203d","type":"function","z":"d7cf668a.1dd428","name":"calculate new dimlevel","func":"msg.currentDimLevel = msg.payload.variable.value;\n\nif (msg.command === \"DecrementPercentageRequest\" && msg.currentDimLevel > 30){\n dimToLevel = msg.currentDimLevel + msg.brightnessChange;\n msg.payload = msg.device + \" \" + dimToLevel;\n return msg;}\nelse{\n dimToLevel = 10;\n msg.payload = msg.device + \" \" + dimToLevel;\n return msg;\n}\n\n\nreturn null;","outputs":1,"noerr":0,"x":2090,"y":715,"wires":[["16c30fec.ff06a"]]},{"id":"af11551c.995418","type":"switch","z":"d7cf668a.1dd428","name":"up or down?","property":"command","propertyType":"msg","rules":[{"t":"eq","v":"IncrementPercentageRequest","vt":"str"},{"t":"eq","v":"DecrementPercentageRequest","vt":"str"}],"checkall":"true","outputs":2,"x":1780,"y":655,"wires":[["1810d788.13b7a8"],["eca55fc3.8203d"]]},{"id":"1810d788.13b7a8","type":"function","z":"d7cf668a.1dd428","name":"calculate new dimlevel up","func":"msg.currentDimLevel = msg.payload.variable.value;\n\n\nif (msg.command === \"IncrementPercentageRequest\" && msg.currentDimLevel <= 75){\n dimToLevel = msg.currentDimLevel + msg.brightnessChange;\n msg.payload = msg.device + \" \" + dimToLevel;\n msg.brightness = dimToLevel;\n return msg;}\nelse{\n dimToLevel = 100;\n msg.payload = msg.device + \" \" + dimToLevel;\n msg.brightness = dimToLevel;\n return msg;\n}\n\nreturn null;","outputs":1,"noerr":0,"x":2100,"y":655,"wires":[["16c30fec.ff06a"]]},{"id":"61ddebf2.06c604","type":"http request","z":"d7cf668a.1dd428","name":"turnOn","method":"GET","ret":"txt","url":"http://localhost/api/device/{{device}}/turnOn","tls":"","x":1206,"y":487,"wires":[[]]},{"id":"6f71be33.06fa1","type":"http request","z":"d7cf668a.1dd428","name":"turnOff","method":"GET","ret":"txt","url":"http://localhost/api/device/{{device}}/turnOff","tls":"","x":1214,"y":529,"wires":[[]]},{"id":"16c30fec.ff06a","type":"http request","z":"d7cf668a.1dd428","name":"change brightness","method":"GET","ret":"txt","url":"http://localhost/api/device/{{device}}/changeDimlevelTo?dimlevel={({brightness}})","tls":"","x":2404,"y":641,"wires":[[]]},{"id":"1dde58d1.d01427","type":"alexa-home-conf","z":"","username":"MyBridgeAccount"}]
Example for my "TV & Audioreceiver"
Uses buttons for changing volume and on/off with pimatic switches.
[{"id":"3ac38b8f.16fb54","type":"switch","z":"9cfb4d50.1dbe","name":"pimatic action","property":"command","propertyType":"msg","rules":[{"t":"eq","v":"TurnOnRequest","vt":"str"},{"t":"eq","v":"TurnOffRequest","vt":"str"},{"t":"eq","v":"SetPercentageRequest","vt":"str"},{"t":"eq","v":"DecrementPercentageRequest","vt":"str"},{"t":"eq","v":"IncrementPercentageRequest","vt":"str"}],"checkall":"false","outputs":5,"x":517,"y":140.66665649414062,"wires":[["1a4f0629.08e95a"],["818bf535.29e118"],[],["afdcb1fe.7b482"],["e4fe2b22.bc9498"]]},{"id":"e4fe2b22.bc9498","type":"http request","z":"9cfb4d50.1dbe","name":"volup","method":"GET","ret":"obj","url":"http://rasp/api/device/av/buttonPressed?buttonId=av_volup","tls":"","x":799.2222290039062,"y":264,"wires":[["d77f2642.d5d438"]]},{"id":"afdcb1fe.7b482","type":"http request","z":"9cfb4d50.1dbe","name":"voldown","method":"GET","ret":"obj","url":"http://rasp/api/device/av/buttonPressed?buttonId=av_voldown","tls":"","x":809.2222290039062,"y":304,"wires":[["5872f591.f643cc"]]},{"id":"1a4f0629.08e95a","type":"http request","z":"9cfb4d50.1dbe","name":"turnOn","method":"GET","ret":"txt","url":"http://rasp/api/device/verstaerker/turnOn","tls":"","x":819.2222290039062,"y":44,"wires":[["3d1c4735.8a9cd8"]]},{"id":"818bf535.29e118","type":"http request","z":"9cfb4d50.1dbe","name":"turnOff","method":"GET","ret":"txt","url":"http://localhost/api/device/verstaerker/turnOff","tls":"","x":827.2222290039062,"y":86,"wires":[["1ff403ce.f29c7c"]]},{"id":"4f1ead7.39ea154","type":"alexa-home","z":"9cfb4d50.1dbe","conf":"1dde58d1.d01427","device":"2821","acknoledge":true,"name":"Verstärker","topic":"","x":99.22222900390625,"y":104,"wires":[["3ac38b8f.16fb54"]]},{"id":"a2295bbf.648028","type":"alexa-home","z":"9cfb4d50.1dbe","conf":"1dde58d1.d01427","device":"2852","acknoledge":true,"name":"Fernseher","topic":"","x":129.22222900390625,"y":424,"wires":[["a5d179f0.b4b008"]]},{"id":"a5d179f0.b4b008","type":"switch","z":"9cfb4d50.1dbe","name":"pimatic action","property":"command","propertyType":"msg","rules":[{"t":"eq","v":"TurnOnRequest","vt":"str"},{"t":"eq","v":"TurnOffRequest","vt":"str"},{"t":"eq","v":"SetPercentageRequest","vt":"str"},{"t":"eq","v":"DecrementPercentageRequest","vt":"str"},{"t":"eq","v":"IncrementPercentageRequest","vt":"str"}],"checkall":"false","outputs":5,"x":489.22222900390625,"y":484,"wires":[["8de9f104.bcfc8"],["17c1cce3.b3df33"],[],["d91ddaac.87a088"],["ebe39f7c.c9f79"]]},{"id":"d91ddaac.87a088","type":"http request","z":"9cfb4d50.1dbe","name":"tv volup","method":"GET","ret":"obj","url":"http://rasp/api/device/tv-buttons/buttonPressed?buttonId=tv_volup","tls":"","x":781.4444580078125,"y":607.3333435058594,"wires":[["fb96c8cd.e9a538"]]},{"id":"ebe39f7c.c9f79","type":"http request","z":"9cfb4d50.1dbe","name":"tv voldown","method":"GET","ret":"obj","url":"http://rasp/api/device/tv-buttons/buttonPressed?buttonId=tv_voldown","tls":"","x":791.4444580078125,"y":647.3333435058594,"wires":[["fb96c8cd.e9a538"]]},{"id":"8de9f104.bcfc8","type":"http request","z":"9cfb4d50.1dbe","name":"turnOn","method":"GET","ret":"txt","url":"http://rasp/api/device/tv/turnOn","tls":"","x":791.4444580078125,"y":387.3333435058594,"wires":[["fb96c8cd.e9a538"]]},{"id":"17c1cce3.b3df33","type":"http request","z":"9cfb4d50.1dbe","name":"turnOff","method":"GET","ret":"txt","url":"http://localhost/api/device/tv/turnOff","tls":"","x":799.4444580078125,"y":429.3333435058594,"wires":[["fb96c8cd.e9a538"]]},{"id":"3d1c4735.8a9cd8","type":"debug","z":"9cfb4d50.1dbe","name":"","active":true,"console":"false","complete":"true","x":968.5,"y":35,"wires":[]},{"id":"fb96c8cd.e9a538","type":"debug","z":"9cfb4d50.1dbe","name":"","active":true,"console":"false","complete":"false","x":965.5,"y":386,"wires":[]},{"id":"1ff403ce.f29c7c","type":"debug","z":"9cfb4d50.1dbe","name":"","active":true,"console":"false","complete":"true","x":972.5,"y":88,"wires":[]},{"id":"d77f2642.d5d438","type":"debug","z":"9cfb4d50.1dbe","name":"","active":true,"console":"false","complete":"true","x":961,"y":272,"wires":[]},{"id":"5872f591.f643cc","type":"debug","z":"9cfb4d50.1dbe","name":"","active":true,"console":"false","complete":"true","x":962,"y":316,"wires":[]},{"id":"1dde58d1.d01427","type":"alexa-home-conf","z":"","username":"MyBridgeAccount"}]
btw: i have the feeling that nearly every device (pimatic-tradfri and for example pimatic-led) have different actions/variables. we should work on that
so have fun, comment are welcome