1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Integration with Domoticz via Node-Red

Discussion in 'Hyperion Extensions' started by Alex B. Goode, 24 September 2016.

  1. Alex B. Goode

    Alex B. Goode New Member

    Messages:
    11
    Hardware:
    RPi2, RPi3
    Hello folks

    I am playing around home automation using Domoticz platform for dashboard / visualization purposes and Node-Red flow subsystem to make it dynamic

    More or less I am successful and pressing widgets in Domoticz make my predefined wishes happen, so I can turn hyperion off, can turn a rainbow swirl effect, or switch it into external mode for PS4 - here I am using Node-Red to catch events and execute hyperion-remote commands

    Inconsistent situation is about syncing the state of hyperion when I control it manually via command line or mobile app when all commands are not reflected in Domoticz

    So I plan to sync it by catching hyperion JSON feedback and correct the status on Domoticz
    I am thinking of using the feature of forwarder to external jsonServer... As I understand the idea - all commands I send to local hyperion are forwarder into another address specified in forwarder section of the config file

    I am ready to share all info scripts I made for that
    I contribution would be much appreciated on this, any idea is countable

    I tried to use Node-Red's input node TCP for catching call of the forwarder and it even receives the JSON messages... and hangs... and the command line process hangs at this moment too

    That's where I am hanging at the moment
     
  2. redPanther

    redPanther Moderator Developer

    Messages:
    211
    Hardware:
    RPi1/Zero, RPi2, 32/64bit, +Arduino
    You have to close connection after receiving.
     
  3. elfnoir

    elfnoir New Member

    Messages:
    7
    Hardware:
    RPi1/Zero, +Arduino
    Hi,
    I'm interesting to turn ON Hyperion with Random or Xmas script (for example) from a RPI embedded Domoticz, to another RPI embedded KODI+Hyperion; Did you succeed to interrop Domoticz and Hyperion? Do you have some help on it? I try to understand JSON interface and how I should create a script to make the link betwwen 2 RPIs, but I'm a noob!
    Thanks for yout feedback!
     
  4. Alex B. Goode

    Alex B. Goode New Member

    Messages:
    11
    Hardware:
    RPi2, RPi3
    It's not clear from your question what you expect from linking of two Hyperions.
    Just in case if you need to activate one of the effects from Domoticz (or from whatever else) I would suggest using the command line interface

    Moving this way you don't have to deep dive into details of Hyperion JSON interface.
    You can do it from Node-Red like me using node type Exec with the command line '/usr/bin/hyperion-remote' and parameters provided via payload.msg
    You can also do it from Domoticz using its internal scripting mechanisms like LUA or Python or even directly from a switch by specifying 'On Action' action (something like script:///usr/bin/hyperion-remote --effect "Rainbow swirl")

    [{"id":"84791c34.6b765","type":"comment","z":"5bdf551a.bc5ebc","name":"by interval","info":"","x":500,"y":640,"wires":[]},{"id":"4d9e9cb8.b2b8a4","type":"inject","z":"5bdf551a.bc5ebc","name":"11:30 pm","topic":"","payload":"{\"interval\": 3, \"max\": 70}","payloadType":"json","repeat":"","crontab":"30 23 * * *","once":false,"x":270,"y":540,"wires":[["1069c807.0cbe98"]]},{"id":"5db0f83a.80a578","type":"comment","z":"5bdf551a.bc5ebc","name":"Night mode","info":"","x":270,"y":580,"wires":[]},{"id":"299b6e42.3a4b92","type":"function","z":"5bdf551a.bc5ebc","name":"svalue1 to %","func":"var v;\nv = msg.payload.svalue1;\nif (v == 100)\n msg.payload = \"--luminance 1\";\nelse\n msg.payload = \"--luminance 0.\" + v;\nreturn msg;","outputs":1,"noerr":0,"x":610,"y":700,"wires":[["b803ba60.4eec78"]]},{"id":"d3ad6066.47faa","type":"tcp in","z":"5bdf551a.bc5ebc","name":"","server":"server","host":"","port":"20444","datamode":"stream","datatype":"utf8","newline":"\\n","topic":"","base64":false,"x":60,"y":1560,"wires":[["823e78d8.2f8828","6b4fe47f.b333dc","cca6071f.28d678","35425154.7f5fbe","4b1a92b7.ad7c9c"]]},{"id":"77fa0727.511428","type":"debug","z":"5bdf551a.bc5ebc","name":"","active":false,"console":"false","complete":"true","x":570,"y":1560,"wires":[]},{"id":"6b4fe47f.b333dc","type":"tcp out","z":"5bdf551a.bc5ebc","host":"","port":"20444","beserver":"reply","base64":true,"end":true,"name":"","x":640,"y":1780,"wires":[]},{"id":"9b5d844d.ff11b8","type":"inject","z":"5bdf551a.bc5ebc","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":80,"y":1680,"wires":[["54a3dd34.1662d4"]]},{"id":"3644f1d6.1c801e","type":"change","z":"5bdf551a.bc5ebc","name":"Off (black)","rules":[{"t":"set","p":"payload","pt":"msg","to":"--color black","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":710,"y":640,"wires":[["b803ba60.4eec78"]]},{"id":"1069c807.0cbe98","type":"function","z":"5bdf551a.bc5ebc","name":"brightness count down","func":"var sec = msg.payload.interval;\nvar myVar = setInterval(myTimer, sec * 1000);\nvar count = msg.payload.max;\nfunction myTimer() {\n node.send([,{payload: {\"svalue1\": count}}]);\n count -= 1;\n if (count <= 11){\n clearInterval(myVar);\n node.send([\n {payload:{\n max: msg.payload.max\n }},\n ]);\n }\n}\nreturn [,];","outputs":"2","noerr":0,"x":490,"y":540,"wires":[["3644f1d6.1c801e","6d111247.e8df6c"],["299b6e42.3a4b92"]]},{"id":"f63c9aff.2d00a8","type":"comment","z":"5bdf551a.bc5ebc","name":"at the end","info":"","x":680,"y":540,"wires":[]},{"id":"31a97180.b3ddbe","type":"function","z":"5bdf551a.bc5ebc","name":"Bright back","func":"var v = msg.payload.max;\nreturn [{payload: \"--luminance 0.\" + v}];\n","outputs":1,"noerr":0,"x":862,"y":600,"wires":[["b803ba60.4eec78"]]},{"id":"6d111247.e8df6c","type":"delay","z":"5bdf551a.bc5ebc","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":800,"y":500,"wires":[["31a97180.b3ddbe"]]},{"id":"823e78d8.2f8828","type":"change","z":"5bdf551a.bc5ebc","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"success\": false, \"error\": null}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":300,"y":1560,"wires":[["77fa0727.511428","3b9b55c8.1b04aa"]]},{"id":"3b9b55c8.1b04aa","type":"json","z":"5bdf551a.bc5ebc","name":"","x":390,"y":1640,"wires":[["77fa0727.511428","54a3dd34.1662d4"]]},{"id":"54a3dd34.1662d4","type":"function","z":"5bdf551a.bc5ebc","name":"","func":"msg.payload = '{\"success\": true}\\n'\n\nreturn msg;","outputs":1,"noerr":0,"x":550,"y":1680,"wires":[["6b4fe47f.b333dc","47fccaec.a77ee4"]]},{"id":"47fccaec.a77ee4","type":"debug","z":"5bdf551a.bc5ebc","name":"","active":false,"console":"false","complete":"false","x":720,"y":1640,"wires":[]},{"id":"4b1a92b7.ad7c9c","type":"debug","z":"5bdf551a.bc5ebc","name":"","active":false,"console":"false","complete":"true","x":290,"y":1780,"wires":[]},{"id":"8dc6d92a.2aa548","type":"function","z":"5bdf551a.bc5ebc","name":"start server","func":"var net = global.get('net')\n\nvar port = 12345; //The same port that the server is listening on\n\nvar server = global.get('hyper')\nif (server === undefined) {\n server = net.createServer();\n global.set('hyper', server);\n server.on('connection', handleConnection);\n\n server.listen(port, function() { \n console.log('server listening to %j', server.address());\n }).on('error', console.log);\n}\n\nfunction handleConnection(conn) { \n var remoteAddress = conn.remoteAddress + ':' + conn.remotePort;\n console.log('new client connection from %s', remoteAddress);\n flow.set('hyper.conn', conn);\n \n conn.on('data', onConnData);\n conn.once('close', onConnClose);\n conn.on('error', onConnError);\n\n function onConnData(d) {\n// console.log('connection data from %s: %j', remoteAddress, d.toString());\n var buf = new Buffer(256);\n var len = buf.write(d.toString());\n var message = buf.toString('utf8', 0, len);\n console.log(len + \" bytes: \" + message);\n// conn.write('{\"success\": true}\\n');\n node.send([{\"payload\":message},null,null]);\n server.close();\n }\n\n function onConnClose() {\n console.log('connection from %s closed', remoteAddress);\n node.send([null,{\"close\":2},null]);\n }\n\n function onConnError(err) {\n console.log('Connection %s error: %s', remoteAddress, err.message);\n node.send([null,null,{\"error\":3}]);\n }\n}\n","outputs":"3","noerr":0,"x":190,"y":1260,"wires":[["2ccd49a2.b02d16","fa1f3727.790ad8","be398e16.013b1"],["1882f6f3.5392e9"],["e7750094.0eeed"]]},{"id":"cca6071f.28d678","type":"function","z":"5bdf551a.bc5ebc","name":"","func":"\nreturn msg;","outputs":1,"noerr":0,"x":280,"y":1520,"wires":[[]]},{"id":"35425154.7f5fbe","type":"json","z":"5bdf551a.bc5ebc","name":"","x":140,"y":1780,"wires":[["4b1a92b7.ad7c9c"]]},{"id":"28558278.69323e","type":"debug","z":"5bdf551a.bc5ebc","name":"","active":true,"console":"false","complete":"true","x":630,"y":1300,"wires":[]},{"id":"d920d8c7.b52b58","type":"debug","z":"5bdf551a.bc5ebc","name":"","active":true,"console":"false","complete":"true","x":630,"y":1340,"wires":[]},{"id":"7cac898a.2086e8","type":"inject","z":"5bdf551a.bc5ebc","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":60,"y":1180,"wires":[["8dc6d92a.2aa548"]]},{"id":"1882f6f3.5392e9","type":"json","z":"5bdf551a.bc5ebc","name":"","x":490,"y":1300,"wires":[["28558278.69323e"]]},{"id":"e7750094.0eeed","type":"json","z":"5bdf551a.bc5ebc","name":"","x":490,"y":1340,"wires":[["d920d8c7.b52b58"]]},{"id":"2cebb2f0.c96f1e","type":"function","z":"5bdf551a.bc5ebc","name":"report success","func":"var conn = flow.get('hyper.conn');\n//console.log(conn);\nconn.write(msg.payload);\nreturn msg;","outputs":1,"noerr":0,"x":700,"y":1140,"wires":[["42f36625.49bfe8"]]},{"id":"3b99bc39.24c864","type":"tcp request","z":"5bdf551a.bc5ebc","server":"localhost","port":"19444","out":"char","splitc":"\\n","name":"call hyperion","x":470,"y":1140,"wires":[["445d6f4f.93a1c"]]},{"id":"dd4d27a6.b4af88","type":"debug","z":"5bdf551a.bc5ebc","name":"","active":false,"console":"false","complete":"true","x":850,"y":1280,"wires":[]},{"id":"6a71fb6c.561154","type":"comment","z":"5bdf551a.bc5ebc","name":"command","info":"","x":300,"y":1180,"wires":[]},{"id":"445d6f4f.93a1c","type":"function","z":"5bdf551a.bc5ebc","name":"decode buffer","func":"msg.payload = msg.payload.toString('utf8');\nreturn msg;","outputs":1,"noerr":0,"x":580,"y":1200,"wires":[["2cebb2f0.c96f1e"]]},{"id":"42f36625.49bfe8","type":"json","z":"5bdf551a.bc5ebc","name":"","x":830,"y":1080,"wires":[["dd4d27a6.b4af88"]]},{"id":"2ccd49a2.b02d16","type":"delay","z":"5bdf551a.bc5ebc","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"x":262,"y":1140,"wires":[["3b99bc39.24c864","42f36625.49bfe8"]]},{"id":"fa1f3727.790ad8","type":"delay","z":"5bdf551a.bc5ebc","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"x":350,"y":1400,"wires":[[]]},{"id":"c257163b.cdf2c8","type":"debug","z":"5bdf551a.bc5ebc","name":"","active":true,"console":"false","complete":"true","x":630,"y":1260,"wires":[]},{"id":"be398e16.013b1","type":"json","z":"5bdf551a.bc5ebc","name":"","x":490,"y":1260,"wires":[["c257163b.cdf2c8"]]},{"id":"b803ba60.4eec78","type":"exec","z":"5bdf551a.bc5ebc","command":"/usr/bin/hyperion-remote ","addpay":true,"append":"","useSpawn":"","timer":"","name":"Call Hyper","x":890,"y":760,"wires":[[],[],[]]}]
     
    Last edited: 30 October 2016
  5. elfnoir

    elfnoir New Member

    Messages:
    7
    Hardware:
    RPi1/Zero, +Arduino
    Ok...then regarding the 2 RPI, one has Domoticz only (with for example internal adress 192.168.1.1), and another one has KODI+Hyperion (no Domoticz) (with for example internal adress 192.168.1.2).
    I create a dummy switch in Domoticz on 192.168.1.1 RPI, and in 'Action ON' field, if I type "script:///192.168.1.2/usr/hyperion/bin/hyperion-remote --effect 'random'", nothing happend, and I receive no errors messages; could you please tell me what I have to put in the Action ON field on the Domoticz in my 192.168.1.1 RPI please?

    Maybe it's because, on the Hyperion's RPI, if I am in the directory "OpenELEC:~/hyperion/bin", that include "hyperion-remote", if I type "hyperion-remote --effect 'random'", I have the error message "
    -sh: hyperion-remote: not found' ; is it a possible tips?
    Once again sorry if my questions are very 'low level', but I'm noob...
     
  6. TPmodding

    TPmodding Administrator Staff Member Administrator

    Messages:
    913
    Hardware:
    RPi1/Zero, RPi2, RPi3, +Arduino
    on openelec you have to write "./hyperion-remote.sh --effect <name>" you need the addiotional ".sh"
     
  7. elfnoir

    elfnoir New Member

    Messages:
    7
    Hardware:
    RPi1/Zero, +Arduino
    ok, with this writting, no error, thanks!:

    OpenELEC:~/hyperion/effects # ~/hyperion/bin/hyperion-remote.sh --effect 'random'

    hyperion-remote:
    version : V1.03.2 (brindosch-99d9396/d3713a8-1469452981
    build time: Jul 25 2016 06:54:18
    Connected to localhost:19444

    Start effect random

    ...but unfortunately there is no changement on the LED.
    I try with Android app on my telephon to turn off/turn on or with KODI working, or with another effect name, and unfortunately, despite I have the message 'Start effect xxxxx', there is no impact on the light of the LEDs.
    Thanks for your support!
     
  8. Alex B. Goode

    Alex B. Goode New Member

    Messages:
    11
    Hardware:
    RPi2, RPi3
    First of all you need to chose the way you like to go

    Either it could be done from KODI which coexists with Hyperion on the same RPi... in this case you should play around configuring KODI like you started already with the hint of TPmodding.

    Or you should do it via Domoticz and in this case you should have Hyperion command line tools installed on this RPi on order to start local scripts. The approach <script:///192.168.1.2/usr/hyperion/bin/hyperion-remote ...> is not going to work because you try to make it remotely... it's doable but not so easy. If you have Hyperion command line tools installed locally on the same RPi with Domoticz, in this case you may start local scripts like <script:///usr/hyperion/bin/hyperion-remote -h 192.168.1.2 -p 19444...> but specifying remote host with Hyperion service

    But anyway, I think you are moving further having no working basic configuration. As I can see, your basic setup doesn't work even via direct controling by the Android app. If so, you'd better achieve a little success here and only after that go further with remote controlling via Domoticz or KODI
     
  9. elfnoir

    elfnoir New Member

    Messages:
    7
    Hardware:
    RPi1/Zero, +Arduino
    Maybe I was not clear sorry.
    Hyperion is working for me, through Android App, or with KODI running on my RPI.
    The issue is, when I'm typping:

    OpenELEC:
    ~ # ~/hyperion/bin/hyperion-remote.sh --effect 'random'

    there is no modification on the Leds, meaning if I'm looking a movie, Leds are continuing to display correctly the color, or if I choose an effect with the mobile App, it continues to do so, despite the shell said 'Star effect random' or 'Start effect X-mas'...but I also try this think:

    OpenELEC:~ # ~/hyperion/bin/hyperion-remote.sh --effect 'ygbhjbhjlgvyug'
    hyperion-remote:
    version : V1.03.2 (brindosch-99d9396/d3713a8-1469452981
    build time: Jul 25 2016 06:54:18
    Connected to localhost:19444
    Start effect ygbhjbhjlgvyug
    meaning it's not helpfull in troubleshooting because it always saying me it's OK !

    And you're right: before trying to monitore it with the second RPI, I need to succeed locally :)
    Do you have an idea please?
     
  10. Alex B. Goode

    Alex B. Goode New Member

    Messages:
    11
    Hardware:
    RPi2, RPi3
    The guess... try with priority! As I understand, there is mechanism of priorities in Hyperion which makes the priority for execution of the command with (lowest?) priority.