# Problem using msg data in service node

**URL:** https://discourse.nodered.org/t/problem-using-msg-data-in-service-node/51142
**Category:** General
**Created:** [17 September 2021 10:22 UTC](https://discourse.nodered.org/t/problem-using-msg-data-in-service-node/51142 "2021-09-17T10:22:43Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![burton666](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/burton666/32/48143_2.png) [@burton666](https://discourse.nodered.org/u/burton666)
#### Post date: [17 September 2021 10:22 UTC](https://discourse.nodered.org/t/problem-using-msg-data-in-service-node/51142/1 "2021-09-17T10:22:44Z")

</div>

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.

 ![Skärmbild 2021-09-17 122123](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/d/bd128e893f6416b207b503b9d766032ba715f7c4.png)

```auto
[{"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}]

```

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [17 September 2021 10:39 UTC](https://discourse.nodered.org/t/problem-using-msg-data-in-service-node/51142/2 "2021-09-17T10:39:16Z")

</div>

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

---

<div class="post-metadata">

### Author: ![burton666](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/burton666/32/48143_2.png) [@burton666](https://discourse.nodered.org/u/burton666)
#### Post date: [17 September 2021 10:56 UTC](https://discourse.nodered.org/t/problem-using-msg-data-in-service-node/51142/3 "2021-09-17T10:56:40Z")

</div>

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

```

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [17 September 2021 11:04 UTC](https://discourse.nodered.org/t/problem-using-msg-data-in-service-node/51142/4 "2021-09-17T11:04:50Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![burton666](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/burton666/32/48143_2.png) [@burton666](https://discourse.nodered.org/u/burton666)
#### Post date: [17 September 2021 11:34 UTC](https://discourse.nodered.org/t/problem-using-msg-data-in-service-node/51142/5 "2021-09-17T11:34:30Z")

</div>

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 🙂

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [1 October 2021 11:35 UTC](https://discourse.nodered.org/t/problem-using-msg-data-in-service-node/51142/6 "2021-10-01T11:35:27Z")

</div>

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