Problem using msg data in service node

I have tride to create a flow that dims my spotligts depending on the reading from a lux-sensor. But can't figure out how to get the "dimLevel" into my spotligt-service-node. I have tried using debug-nodes and it looks fine to me, but adding the expression {"brigthness_pct":msg.dimLevel} or {"brightness_pct":dimLevel} does not change the brightness. The dimLevel is always a value between 0-100.

[{"id":"89fe933a975b85c0","type":"server-state-changed","z":"8901fd6b7b125477","name":"Motion Köksbord","server":"80866131.268ee","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.motion_koksbord_occupancy","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":220,"y":280,"wires":[["ef6159ecd37432df"],["5ea8ad39e3dde67e"]]},{"id":"911e190a72108921","type":"api-current-state","z":"8901fd6b7b125477","name":"Lux Sensor Kök","server":"80866131.268ee","version":1,"outputs":2,"halt_if":"40000","halt_if_type":"num","halt_if_compare":"lt","override_topic":false,"entity_id":"sensor.ljussensor_kok_aqara_illuminance_lux","state_type":"num","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":660,"y":180,"wires":[["ba9ab3947e75198b"],["f174651b7d3a5f41"]]},{"id":"7f705205844efef4","type":"api-call-service","z":"8901fd6b7b125477","name":"Spotligths Köksbord Dim to Lux-level","server":"80866131.268ee","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.spotlights_koksbord","data":"{\"brightness_pct\":msg.dimLevel,\"transition\":2000}","dataType":"jsonata","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1150,"y":180,"wires":[[]]},{"id":"f174651b7d3a5f41","type":"api-call-service","z":"8901fd6b7b125477","name":"Spotligths Köksbord Off","server":"80866131.268ee","version":1,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.spotlights_koksbord","data":"","dataType":"jsonata","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1130,"y":340,"wires":[[]]},{"id":"5ea8ad39e3dde67e","type":"trigger","z":"8901fd6b7b125477","name":"","op1":"","op2":"0","op1type":"nul","op2type":"str","duration":"5","extend":true,"overrideDelay":false,"units":"min","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":390,"y":340,"wires":[["876b3c3fc28d6419"]]},{"id":"876b3c3fc28d6419","type":"api-current-state","z":"8901fd6b7b125477","name":"Motion Köksbord","server":"80866131.268ee","version":1,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"binary_sensor.motion_koksbord_occupancy","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":670,"y":340,"wires":[["f174651b7d3a5f41"],[]]},{"id":"ef6159ecd37432df","type":"time-range-switch","z":"8901fd6b7b125477","name":"Dag","lat":"60.60001","lon":"17.42701","startTime":"06:00","endTime":"20:00","startOffset":0,"endOffset":0,"x":470,"y":240,"wires":[["911e190a72108921"],["087455724be6fff0"]]},{"id":"087455724be6fff0","type":"api-call-service","z":"8901fd6b7b125477","name":"Spotligths Köksbord 10%","server":"80866131.268ee","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.spotlights_koksbord","data":"{\"brightness_pct\":10}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":690,"y":260,"wires":[[]]},{"id":"ba9ab3947e75198b","type":"function","z":"8901fd6b7b125477","name":"Dimlevel","func":"var dimLevel = parseInt(100-0.0025*msg.payload)\n\nvar newMsg = { payload: msg.payload, dimLevel:dimLevel };\n\nreturn newMsg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":880,"y":180,"wires":[["7f705205844efef4"]]},{"id":"80866131.268ee","type":"server","name":"Home Assistant","legacy":false,"addon":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

What does the message you are sending look like in a debug node?

{"payload":4579,"dimLevel":88,"_msgid":"55cf0e1684d36d1f"}

Is that what you think the service node needs? I presume that is a Home Assistant node. Can you point to the docs for that node please?

Ah, you where right. I was thinking "transition" was defined in ms but it was actually seconds. So a transition of 1000-2000 was a little too much. Thanks for pointing out where to look :slight_smile:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.