Création d'un pont Jeedom vers HA

Et voilà…

[{"id":"6273e9a6.0704e8","type":"http in","z":"3ed32b34.880364","name":"Jeedom In","url":"/jeedom","method":"get","upload":false,"swaggerDoc":"","x":330,"y":350,"wires":[["5be0819d.013f2","82ae502a.84c94","3c3b2c34.7b2924","a173ab89.c1f568"]]},{"id":"5be0819d.013f2","type":"http response","z":"3ed32b34.880364","name":"","statusCode":"","headers":{},"x":520,"y":330,"wires":[]},{"id":"3c3b2c34.7b2924","type":"function","z":"3ed32b34.880364","name":"J2ssio","func":"var host = global.get(\"host\");\nvar token = global.get(\"token\");\n\nvar value = Number(msg.payload.value);\nvar objet_id = Number(msg.payload.id);\nvar entity_id = \"\";\n\nids = global.get(\"ids\");\nnames = global.get(\"names\");\nis_binary = global.get(\"binary\");\n\nentity_id = names[ids.indexOf(objet_id)];\nentity_binary = is_binary[ids.indexOf(objet_id)];\n\nif ( Boolean(entity_binary) ) {\n    if ( value === 1 ) { value = \"On\"; }\n    else { value = \"Off\" }\n}\n\nif ( entity_id === undefined ) {\n    msg.url = \"\";\n    msg.method = \"\";\n    msg.payload = \"\";\n    msg.headers = \"\";\n}\nelse {\n    msg.url = host + \"/api/states/\" + entity_id;\n    msg.method = \"POST\";\n    msg.payload = {\n       'state': value\n    }; \n    msg.headers = {\n        'Authorization': 'Bearer ' + token,\n        'content-type': 'application/json',\n    } ;\n}\nreturn msg;\n","outputs":1,"noerr":0,"x":520,"y":410,"wires":[["27ece8de.b09948"]]},{"id":"27ece8de.b09948","type":"switch","z":"3ed32b34.880364","name":"","property":"payload","propertyType":"msg","rules":[{"t":"nempty"},{"t":"else"}],"checkall":"false","repair":false,"outputs":2,"x":660,"y":410,"wires":[["76c583a2.063fcc"],[]]},{"id":"76c583a2.063fcc","type":"https-node","z":"3ed32b34.880364","name":"Hassio Out","method":"use","ret":"txt","url":"","authorized":false,"agent":true,"x":810,"y":410,"wires":[[]]},{"id":"1d321a0d.73bf76","type":"inject","z":"3ed32b34.880364","name":"","topic":"","payload":"","payloadType":"date","repeat":"900","crontab":"","once":true,"onceDelay":"2","x":360,"y":480,"wires":[["409aeef2.d2993"]]},{"id":"409aeef2.d2993","type":"file in","z":"3ed32b34.880364","name":"Sensors","filename":"/config/resources/jeedom/sensors.yaml","format":"utf8","chunk":false,"sendError":false,"encoding":"none","x":530,"y":480,"wires":[["dfdd3eb6.4b15e"]]},{"id":"dfdd3eb6.4b15e","type":"yaml","z":"3ed32b34.880364","property":"payload","name":"","x":680,"y":480,"wires":[["322c70df.d7297","eb15bf94.2e284"]]},{"id":"322c70df.d7297","type":"function","z":"3ed32b34.880364","name":"Charge","func":"var array_id = [];\nvar array_name = [];\nvar array_binary = [];\nglobal.set(\"ids\",\"\");\nglobal.set(\"names\",\"\");\nglobal.set(\"binary\",\"\");\nfor (var i=0; i<msg.payload.sensors.length;i++) {\n  array_id.push(msg.payload.sensors[i].id);\n  array_name.push(msg.payload.sensors[i].name);\n  array_binary.push(msg.payload.sensors[i].binary);\n}\nglobal.set(\"ids\", array_id);\nglobal.set(\"names\", array_name);\nglobal.set(\"binary\", array_binary);\nreturn msg;\n","outputs":1,"noerr":0,"x":830,"y":480,"wires":[[]]}]

Il faut créer un fichier des « sensors » que jeedom publie et que tu veux connaitre dans HA.

sensors:
- name: sensor.oeil_salon_presence
  binary: true
  id: 35
- name: sensor.oeil_salon_temperature
  binary: false
  id: 36 

Les id sont ceux de Jeedom.

Il faut également créer les variables qui sont utilisées.

[{"id":"65ed6d48.d79604","type":"inject","z":"3ed32b34.880364","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"onceDelay":"1","x":430,"y":170,"wires":[["47249f9b.aa531"]]},{"id":"47249f9b.aa531","type":"change","z":"3ed32b34.880364","name":"Parameters","rules":[{"t":"set","p":"host","pt":"global","to":"https://@IP_HA:8123","tot":"str"},{"t":"set","p":"token","pt":"global","to":"Le_Token","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":610,"y":170,"wires":[[]]}]

Il y a sûrement des trucs à améliorer la dedans. A l’époque mes connaissances en javascript étaient nulles ou presque. Deux ans après, je n’ai pas vraiment progressé. Je ne me suis donc pas replongé dans le code.

1 « J'aime »