Jeg sliter også med å få til dimmefunksjonen på denne bryteren.
Jeg fant et glimrende script her: https://marknygaard.dk/blog/2020/03/hue-dimmer-script-in-node-red/
som jeg har modifisert. Men loopen som skal dimme kontinuerlig fungerer ikke. Og jeg klarer ikke å se hvorfor.
Kanskje noen av dere som er flinkere i programmering enn meg ser det umiddelbart.
Her er min Node-RED flow slik den står nå:
[{"id":"d5257804.c57068","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"a1d86f20.07bc9","type":"server-state-changed","z":"d5257804.c57068","d":true,"name":"Lysbryter - TV-krok","server":"c20c4f32.3a7de","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sensor.namron_lysbryter_stue_action","entityidfiltertype":"exact","outputinitially":false,"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,"x":970,"y":640,"wires":[["21a46ffb.e33998"]]},{"id":"fa69cafa.52b978","type":"api-call-service","z":"d5257804.c57068","name":"Lys - TV-krok","server":"c20c4f32.3a7de","version":1,"debugenabled":false,"service_domain":"","service":"","entityId":"","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1750,"y":640,"wires":[[]]},{"id":"bcb896b1.4765a8","type":"mqtt in","z":"d5257804.c57068","name":"Lysbryter - TV-krok - MQTT","topic":"zigbee2mqtt/Namron - Lysbryter - Stue/action","qos":"0","datatype":"utf8","broker":"3d06dee0.f98b0a","x":980,"y":540,"wires":[["21a46ffb.e33998"]]},{"id":"21a46ffb.e33998","type":"function","z":"d5257804.c57068","name":"Dimming","func":"var entity = 'light.tv_krok_spot_oystein';\nvar interval = 10;\n/*\nfunction name(parameter1, parameter2, parameter3) {\n // code to be executed\n}\n*/\n\nconst globalHomeAssistant = global.get('homeassistant');\nvar brightness = globalHomeAssistant.homeAssistant.states[entity].attributes.brightness || 0;\nvar state = globalHomeAssistant.homeAssistant.states[entity].state;\nvar delay = 500;\nflow.set('press', false);\n\nif (!msg.payload.hasOwnProperty('action')) msg.payload.action = \"\";\nvar newMsg = { payload: {} };\n\nif ( msg.payload == \"on_l3\" ) {\n if ( state == \"on\" && brightness > 0 ) {\n newMsg.payload = {\n domain: 'light',\n service: 'turn_on',\n data: { entity_id: entity, brightness: 255, transition: 1 }\n }; \n } else {\n newMsg.payload = {\n domain: 'light',\n service: 'turn_on',\n data: { entity_id: entity }\n };\n }\n}\n\nif ( msg.payload == \"brightness_move_up_l3\" ) {\n flow.set('press', true);\n if ( brightness < 255 ) {\n newMsg.payload = {\n domain: 'light',\n service: 'turn_on',\n data: { entity_id: entity, brightness: brightness + interval, transition: 1 }\n };\n } else { \n flow.set('press', false);\n return null\n }\n}\n\nif ( msg.payload == \"brightness_move_down_l3\" ) {\n flow.set('press', true);\n if ( brightness > 0 ) {\n newMsg.payload = {\n domain: 'light',\n service: 'turn_on',\n data: { entity_id: entity, brightness: brightness - interval, transition: 1 }\n };\n } else {\n flow.set('press', false);\n return null\n }\n}\n\nif ( msg.payload == \"brightness_stop_l3\" ) {\n flow.set('press', false)\n return null;\n}\n\nif ( msg.payload == \"brightness_stop_l3\" ) {\n flow.set('press', false)\n if ( brightness <= 0 ) {\n newMsg.payload = {\n domain: 'light',\n service: 'turn_off',\n data: { entity_id: entity }\n };\n } else {\n return null;\n }\n}\n\nif ( msg.payload == \"off_l3\" ) {\n newMsg.payload = {\n domain: 'light',\n service: 'turn_off',\n data: { entity_id: entity }\n \n };\n}\n\nif ( msg.payload === \"\" ) {\n return null;\n}\n\nreturn [newMsg, msg]","outputs":2,"noerr":0,"initialize":"","finalize":"","x":1420,"y":640,"wires":[["fa69cafa.52b978"],["c47689ea.546c3"]]},{"id":"fdf500e0.18291","type":"switch","z":"d5257804.c57068","name":"Control loop","property":"press","propertyType":"flow","rules":[{"t":"eq","v":"true","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":1510,"y":820,"wires":[["21a46ffb.e33998","9cad79a4.d58ad8"]]},{"id":"c47689ea.546c3","type":"delay","z":"d5257804.c57068","name":"Delay","pauseType":"delay","timeout":"500","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1350,"y":820,"wires":[["fdf500e0.18291"]]},{"id":"9cad79a4.d58ad8","type":"debug","z":"d5257804.c57068","name":"Debug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1870,"y":820,"wires":[]},{"id":"c20c4f32.3a7de","type":"server","name":"Home Assistant","addon":true},{"id":"3d06dee0.f98b0a","type":"mqtt-broker","name":"localhost","broker":"mqtt://core-mosquitto","port":"1883","tls":"","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]