-
Notifications
You must be signed in to change notification settings - Fork 0
/
node-red_code
1 lines (1 loc) · 19.3 KB
/
node-red_code
1
[{"id":"69f1dd8d.ee42d4","type":"server-state-changed","z":"4874f9b0.953e68","name":"Botonera IKEA Control Luces Salón","server":"4ce1eb94.345c74","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sensor.panel_salon_action","entityidfiltertype":"exact","outputinitially":true,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":200,"y":540,"wires":[["7f75862f.3bd728","805b1c05.56a02","6096b87c.f0ef88"]]},{"id":"805b1c05.56a02","type":"switch","z":"4874f9b0.953e68","name":"BRIGHTNESS","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"brightness_up_click","vt":"str"},{"t":"eq","v":"brightness_up_hold","vt":"str"},{"t":"eq","v":"brightness_up_release","vt":"str"},{"t":"eq","v":"brightness_down_click","vt":"str"},{"t":"eq","v":"brightness_down_hold","vt":"str"},{"t":"eq","v":"brightness_down_release","vt":"str"}],"checkall":"true","repair":false,"outputs":6,"x":480,"y":540,"wires":[["7d655a06.e7a964"],["5b9576fe.326108"],["5b9576fe.326108"],["7d655a06.e7a964"],["24cc6648.9b3bea"],["24cc6648.9b3bea"]]},{"id":"7f75862f.3bd728","type":"switch","z":"4874f9b0.953e68","name":"TOGGLE","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"toggle","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":460,"y":300,"wires":[["d7d21e0c.2f3fc","2ff55e28.caacb2"]]},{"id":"6096b87c.f0ef88","type":"switch","z":"4874f9b0.953e68","name":"ARROW","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"arrow_left_click","vt":"str"},{"t":"eq","v":"arrow_left_hold","vt":"str"},{"t":"eq","v":"arrow_left_release","vt":"str"},{"t":"eq","v":"arrow_right_click","vt":"str"},{"t":"eq","v":"arrow_right_hold","vt":"str"},{"t":"eq","v":"arrow_right_release","vt":"str"}],"checkall":"true","repair":false,"outputs":6,"x":460,"y":840,"wires":[["a754471c.f44ee8"],["a754471c.f44ee8"],[],["be88aa6c.e8dba8"],["be88aa6c.e8dba8"],[]]},{"id":"d7d21e0c.2f3fc","type":"trigger","z":"4874f9b0.953e68","name":"","op1":"","op2":"true","op1type":"nul","op2type":"bool","duration":"1000","extend":true,"overrideDelay":false,"units":"ms","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":660,"y":320,"wires":[["d86f074e.4ec3f8"]]},{"id":"3377f879.5bfb68","type":"server-state-changed","z":"4874f9b0.953e68","name":"Estado lámpara lectura ","server":"4ce1eb94.345c74","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"light.lampara_lectura","entityidfiltertype":"exact","outputinitially":true,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":500,"y":120,"wires":[[]]},{"id":"ac91d0d2.2f1cb","type":"server-state-changed","z":"4874f9b0.953e68","name":"Estado lámpara rincón ","server":"4ce1eb94.345c74","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"light.lampara_rincon","entityidfiltertype":"exact","outputinitially":true,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":740,"y":120,"wires":[[]]},{"id":"38a793d4.1b05fc","type":"inject","z":"4874f9b0.953e68","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"toggle","payloadType":"str","x":190,"y":300,"wires":[["7f75862f.3bd728"]]},{"id":"f8b8db60.9af388","type":"switch","z":"4874f9b0.953e68","name":"QUE LAMPARA?","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"num"},{"t":"eq","v":"2","vt":"num"},{"t":"eq","v":"3","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":1090,"y":320,"wires":[["e4fb662f.4a2ae8","118bbe6d.eec5b2"],["7f562d8c.d2ff94"],["66e3ed85.ceee84"]]},{"id":"7f562d8c.d2ff94","type":"api-call-service","z":"4874f9b0.953e68","name":"Toggle Luz Lectura","server":"4ce1eb94.345c74","version":3,"debugenabled":false,"service_domain":"light","service":"toggle","entityId":"light.lampara_lectura","data":"","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1410,"y":300,"wires":[["e4fb662f.4a2ae8","4d232ffe.8b9df"]]},{"id":"66e3ed85.ceee84","type":"api-call-service","z":"4874f9b0.953e68","name":"Toggle Luz Rincón","server":"4ce1eb94.345c74","version":3,"debugenabled":false,"service_domain":"light","service":"toggle","entityId":"light.lampara_rincon","data":"","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1410,"y":360,"wires":[["e4fb662f.4a2ae8","61eea034.7f3a4"]]},{"id":"2ff55e28.caacb2","type":"function","z":"4874f9b0.953e68","name":"Sumador de pulsos","func":"// \ncount = flow.get ('count') //\nif (count === undefined){\n count=0 \n}\nif (count >= 4){\n count=0\n}\nmsg.payload=count+1\nflow.set ('count', msg.payload)\n\n\n\n// DEVOLUCION DATOS\n//msg.payload = Math.round(newpayload);\n//msg.payload = Math.round(newpayload)+\" \"+unit\n//msg.unit_of_measurement = unit;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":670,"y":260,"wires":[[]]},{"id":"e4fb662f.4a2ae8","type":"change","z":"4874f9b0.953e68","name":"Reset count","rules":[{"t":"set","p":"count","pt":"flow","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":1630,"y":220,"wires":[["d86f074e.4ec3f8"]]},{"id":"62fcac74.d2c8c4","type":"change","z":"4874f9b0.953e68","name":"Obtener brillo actual","rules":[{"t":"set","p":"brillo","pt":"msg","to":"data.attributes.brightness","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1400,"y":540,"wires":[["6d3f057.ade29fc"]]},{"id":"4d232ffe.8b9df","type":"change","z":"4874f9b0.953e68","name":"Lampara Activa Lectura","rules":[{"t":"set","p":"quelampara","pt":"flow","to":"lectura","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"lectura","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1670,"y":300,"wires":[[]]},{"id":"61eea034.7f3a4","type":"change","z":"4874f9b0.953e68","name":"Lampara Activa Rincon","rules":[{"t":"set","p":"quelampara","pt":"flow","to":"rincon","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"rincon","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1670,"y":360,"wires":[[]]},{"id":"118bbe6d.eec5b2","type":"function","z":"4874f9b0.953e68","name":"Cambio de lampara","func":"// objetos\n//var payload = {}:\n//var newpayload = {};\nvar quelampara = {};\nif (quelampara === undefined){\n quelampara=\"\" \n}\nantquelampara = flow.get ('quelampara') //\n \nif (antquelampara == 'lectura'){\n quelampara='rincon' \n}\nif (antquelampara == 'rincon'){\n quelampara='lectura'\n} \nflow.set ('quelampara', quelampara)\n \n \n \n// DEVOLUCION DATOS\nmsg.payload = quelampara;\n//msg.antquelampara=antquelampara\n//msg.quelampara = quelampara;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1330,"y":200,"wires":[[]]},{"id":"add22b90.783dd8","type":"function","z":"4874f9b0.953e68","name":"Incrementos / decrementos BRILLO","func":"// Definimos variables\nvar nuevobrillo = {};\n//var newpayload = {};\n//\n//brillo = flow.get ('brillo_salon') //\nbrillo = msg.brillo\nif (brillo === undefined){\n brillo=0 \n}\n\n// Segun boton sube o baja el valor del brillo\nif ( msg.payload== 'brightness_up_hold'){\nnuevobrillo=brillo+5\n}\nif ( msg.payload== 'brightness_down_hold'){\nnuevobrillo=brillo-5\n}\n// Con los botones de Click los saltos son de 25 % \nif ( msg.payload== 'brightness_up_click'){\nnuevobrillo=brillo+25\n}\nif ( msg.payload== 'brightness_down_click'){\nnuevobrillo=brillo-25\n}\n\nif ( nuevobrillo <= -1){\n nuevobrillo = 0 \n}\nif ( nuevobrillo >= 101){\n nuevobrillo = 100 \n}\nflow.set ('brillo_salon', nuevobrillo)\n\n\n\n// DEVOLUCION DATOS\n//msg.payload = Math.round(newpayload);\n//msg.payload = Math.round(newpayload)+\" \"+unit\n//msg.brillo = nuevobrillo;\nmsg.payload = nuevobrillo;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":930,"y":660,"wires":[["6a10aa30.d171a4"]]},{"id":"5b9576fe.326108","type":"trigger","z":"4874f9b0.953e68","name":"","op1":"","op2":"true","op1type":"pay","op2type":"bool","duration":"-100","extend":true,"overrideDelay":false,"units":"ms","reset":"brightness_up_release","bytopic":"all","topic":"topic","outputs":1,"x":700,"y":500,"wires":[["7d655a06.e7a964"]]},{"id":"24cc6648.9b3bea","type":"trigger","z":"4874f9b0.953e68","name":"","op1":"","op2":"true","op1type":"pay","op2type":"bool","duration":"-100","extend":true,"overrideDelay":false,"units":"ms","reset":"brightness_down_release","bytopic":"all","topic":"topic","outputs":1,"x":700,"y":580,"wires":[["7d655a06.e7a964"]]},{"id":"377a140b.336d8c","type":"api-call-service","z":"4874f9b0.953e68","name":"Cambiar brillo lectura","server":"4ce1eb94.345c74","version":3,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.lampara_lectura","data":"{ \"brightness_pct\": {{payload}}}","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1460,"y":640,"wires":[[]]},{"id":"d17a9791.cb1198","type":"api-call-service","z":"4874f9b0.953e68","name":"Cambiar brillo rincon","server":"4ce1eb94.345c74","version":3,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.lampara_rincon","data":"{ \"brightness_pct\": {{payload}}}","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1460,"y":700,"wires":[[]]},{"id":"6a10aa30.d171a4","type":"switch","z":"4874f9b0.953e68","name":"QUE LAMPARA?","property":"quelampara","propertyType":"flow","rules":[{"t":"eq","v":"lectura","vt":"str"},{"t":"eq","v":"rincon","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":1210,"y":660,"wires":[["377a140b.336d8c"],["d17a9791.cb1198"]]},{"id":"7d655a06.e7a964","type":"switch","z":"4874f9b0.953e68","name":"QUE LAMPARA?","property":"quelampara","propertyType":"flow","rules":[{"t":"eq","v":"lectura","vt":"str"},{"t":"eq","v":"rincon","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":950,"y":540,"wires":[["c6582b1a.a816f8"],["f3a1ae20.ebd08"]]},{"id":"f3a1ae20.ebd08","type":"api-current-state","z":"4874f9b0.953e68","name":"Estado de la rincon","server":"2e0f828a.d95dbe","version":2,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"light.lampara_rincon","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"data","propertyType":"msg","value":"","valueType":"entity"},{"property":"status","propertyType":"msg","value":"","valueType":"entityState"}],"x":1170,"y":560,"wires":[["62fcac74.d2c8c4"]]},{"id":"c6582b1a.a816f8","type":"api-current-state","z":"4874f9b0.953e68","name":"Estado de la lectura","server":"2e0f828a.d95dbe","version":2,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"light.lampara_lectura","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"data","propertyType":"msg","value":"","valueType":"entity"},{"property":"status","propertyType":"msg","value":"","valueType":"entityState"}],"x":1170,"y":500,"wires":[["62fcac74.d2c8c4"]]},{"id":"6d3f057.ade29fc","type":"range","z":"4874f9b0.953e68","minin":"0","maxin":"255","minout":"0","maxout":"100","action":"clamp","round":true,"property":"brillo","name":"","x":680,"y":660,"wires":[["add22b90.783dd8"]]},{"id":"9cc50750.c87c88","type":"comment","z":"4874f9b0.953e68","name":"Comentarios funcion Cambio lamapara","info":"Esta función tiene el proposito de conmutar la luz sobre la que el sistema mantiene el control para brillo y color. Crea la variable \"quelampara\" que se utilizará en otras partes del flujo.","x":1390,"y":160,"wires":[]},{"id":"44335730.e6b8c8","type":"comment","z":"4874f9b0.953e68","name":"Comentarios funcion Sumador de pulsos","info":"Esta función tiene el proposito de sumar los click consecutivos que se le dan al pulsador toggle del mando IKEA.\nHemos creado el flow con los siguientes criterios:\n3 pulsos hace toggle sobre lampara_rincon\n2 pulsos hace toggle sobre lampara_lectura\n1 pulso cambia memoria de última lampara editada\n\nSe encuentra limitado a 3 pulsos pero se podrían poner mas y con ello controlar mas dispositivos.\n\nEl mando de brillo actuará sobre la última lampara actuada independiente de si está encendida o apagada.\nCrea la variable \"count\" que se utilizará en otras partes del flujo.","x":740,"y":220,"wires":[]},{"id":"9d103147.c6bdf","type":"comment","z":"4874f9b0.953e68","name":"Comentarios Trigger","info":"Mediante este trigger dispararemos el resto del flujo 1000 ms despues del ultimo click. Tiempo configurable según preferencias.","x":670,"y":380,"wires":[]},{"id":"baa09b9b.c67098","type":"comment","z":"4874f9b0.953e68","name":"Comentarios Set","info":"En este Change pasamos los parámetros de la variable flow.count al msg.payload","x":880,"y":380,"wires":[]},{"id":"ff274ca0.188b9","type":"comment","z":"4874f9b0.953e68","name":"Luces del Salon","info":"","x":100,"y":40,"wires":[]},{"id":"d86f074e.4ec3f8","type":"change","z":"4874f9b0.953e68","name":"Count Set","rules":[{"t":"set","p":"payload","pt":"msg","to":"count","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":880,"y":320,"wires":[["f8b8db60.9af388"]]},{"id":"8f066d14.5a36e","type":"comment","z":"4874f9b0.953e68","name":"Comentarios QUELAMPARA?","info":"En este y todos los switch similares discriminamos para qúe lampará iran los comandos entregados.","x":1120,"y":380,"wires":[]},{"id":"a754471c.f44ee8","type":"api-call-service","z":"4874f9b0.953e68","name":"Toggle Luz Sillones","server":"4ce1eb94.345c74","version":3,"debugenabled":false,"service_domain":"light","service":"toggle","entityId":"light.luz_sillones","data":"","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":690,"y":800,"wires":[[]]},{"id":"be88aa6c.e8dba8","type":"api-call-service","z":"4874f9b0.953e68","name":"Toggle Luz Comedor","server":"4ce1eb94.345c74","version":3,"debugenabled":false,"service_domain":"light","service":"toggle","entityId":"light.luz_comedor","data":"","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":700,"y":860,"wires":[[]]},{"id":"11bd3a48.d98d86","type":"comment","z":"4874f9b0.953e68","name":"Comentarios funcion ARROW","info":"Como el resto de las luces del salon no son dimmables utilizo ests botones para simplemente encender y apagar las luces del techo.\nPodría haber utilizado esta pareja de botones para variar el color de las otras lamparas con un flujo similar al del brillo pero no lo he visto util.","x":700,"y":740,"wires":[]},{"id":"e1e43bb1.0a4f18","type":"comment","z":"4874f9b0.953e68","name":"Comentarios función BRIGHTNESS","info":"Este mando tiene cuatro botones que poseen tres salidas diferentes: click, hold y release.\nEn este caso para controlar el brillo he utilizado la opcion click para subir/bajar el brillo en pasos de 25 %.\nLa función hold dispara un trigger que envia pulsos de subida/bajada de brillo de 5 en 5 % hasta que se produce la funcion release que es cuando deja de enviar estos pulsos. \nEl punto de partida del conteo del brillo se toma de la lectura de parámetros de la bombilla.\nEl número que se enviará a la bombilla es calculado por la función \"Incrementos/decrementos BRILLO\" siempre con los topes de 0 y 100.","x":720,"y":440,"wires":[]},{"id":"79c9fd0b.feef64","type":"server-state-changed","z":"4874f9b0.953e68","name":"Estado luz Comedor","server":"4ce1eb94.345c74","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"light.luz_comedor","entityidfiltertype":"exact","outputinitially":true,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":970,"y":120,"wires":[[]]},{"id":"3ebde45.ae4c61c","type":"server-state-changed","z":"4874f9b0.953e68","name":"Estado luz Sillones","server":"4ce1eb94.345c74","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"light.luz_sillones","entityidfiltertype":"exact","outputinitially":true,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":1190,"y":120,"wires":[[]]},{"id":"3f8cf840.8ad118","type":"comment","z":"4874f9b0.953e68","name":"Comentariosbotonera IKEA-TRADFRI","info":"Este mando tiene un botón central con la función toggel rodeado de cuatro botones que poseen tres salidas diferentes: click, hold y release.\n","x":210,"y":600,"wires":[]},{"id":"4ce1eb94.345c74","type":"server","name":"Home Assistant","version":1,"legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true},{"id":"2e0f828a.d95dbe","type":"server","name":"Home Assistant","version":1,"legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":false}]