# On/off Ikea Tradfri with Loxone

**URL:** <https://discourse.nodered.org/t/on-off-ikea-tradfri-with-loxone/74649>\
**Category:** General\
**Created:** [3 February 2023 10:42 UTC](https://discourse.nodered.org/t/on-off-ikea-tradfri-with-loxone/74649 "2023-02-03T10:42:32Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jkosatko](https://avatars.discourse-cdn.com/v4/letter/j/b9bd4f/32.png) [@jkosatko](https://discourse.nodered.org/u/jkosatko)\
**Post date:** [3 February 2023 10:42 UTC](https://discourse.nodered.org/t/on-off-ikea-tradfri-with-loxone/74649/1 "2023-02-03T10:42:32Z")

</div>

Hello all,

I have started with NR few hours ago...

I am trying to achieve simple thing. I would like to control Ikea sockets connected to Ikea Tradfri gateway via Loxone. I have setup NR and added two paletts node-red-contrib-ikea-tradfi and node-red-contrib-loxone and connected them to the Ikea Tradfri gateway and Loxone miniserver.

I can manage Ikea socket via simple inject on and off to the socket and it is working fine.

I have created virtual switch in Loxone config and I can see it in NR. If I press it in Loxone app, it sends 0 and 1 to NR, I can see it via debug.

I wrote function to convert 0/1 to off/on. If I see debug output from function it successfully converts 0/1 to off/on

> if (msg.payload == 0) {  
> msg.payload = "off";  
> return msg;  
> }  
> else if (msg.payload == 1) {  
> msg.payload = "on";  
> return msg;  
> }  
> return null;

But if I connect output from the function to the Ikea socket I have this error message:

> Invalid message received, using node config!  
> Invalid value "Lampička Honza" supplied to : TradfriSwitchControlMessage/0: Partial\<{ topic: (Int | Array), payload: TradfriSwitchControlAction }\>/topic: (Int | Array)/0: Int  
> Invalid value "Lampička Honza" supplied to : TradfriSwitchControlMessage/0: Partial\<{ topic: (Int | Array), payload: TradfriSwitchControlAction }\>/topic: (Int | Array)/1: Array

What am I doing wrong?

Thanks

Jan K.

---

<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:** [3 February 2023 10:57 UTC](https://discourse.nodered.org/t/on-off-ikea-tradfri-with-loxone/74649/2 "2023-02-03T10:57:46Z")

</div>

Welcome to the forum @jkosatko

Feed the inject nodes that work to switch it on/off into a debug node and show us what they show. Then feed the messages that do not work into a debug node and show us what _they_ show.

---

<div class="post-metadata">

**Author:** ![jkosatko](https://avatars.discourse-cdn.com/v4/letter/j/b9bd4f/32.png) [@jkosatko](https://discourse.nodered.org/u/jkosatko)\
**Post date:** [3 February 2023 15:23 UTC](https://discourse.nodered.org/t/on-off-ikea-tradfri-with-loxone/74649/3 "2023-02-03T15:23:37Z")

</div>

This is result of inject to switch it on:

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/9/b9396440396cda4488a1efabbce3bb81c50be788.png)

this is output form Loxone virtual switch button:

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/6/564f62156c9c12b7c6ec5e1b75c162feb24e8fda.png)

---

<div class="post-metadata">

**Author:** ![jkosatko](https://avatars.discourse-cdn.com/v4/letter/j/b9bd4f/32.png) [@jkosatko](https://discourse.nodered.org/u/jkosatko)\
**Post date:** [3 February 2023 15:24 UTC](https://discourse.nodered.org/t/on-off-ikea-tradfri-with-loxone/74649/4 "2023-02-03T15:24:20Z")

</div>

this is result of my "convert" function:

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/2/12cc916ac7f639a394bf9c34cb77d71700289861.png)

which is in addition strange, because it should be "on" as per function:

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/f/ef17120c5caea4939f5714d09ad05815fe736d45.png)

Thanks

---

<div class="post-metadata">

**Author:** ![jkosatko](https://avatars.discourse-cdn.com/v4/letter/j/b9bd4f/32.png) [@jkosatko](https://discourse.nodered.org/u/jkosatko)\
**Post date:** [3 February 2023 15:31 UTC](https://discourse.nodered.org/t/on-off-ikea-tradfri-with-loxone/74649/5 "2023-02-03T15:31:08Z")

</div>

This is both "environments" separated:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/1/311e3e6d2e2fdd9b68994b80167b877c6d46c869.png)  
and this is when I receive error message:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/b/3b88a5d5d848af5f3523027c79b312c8549c95e7.png)

---

<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:** [3 February 2023 16:05 UTC](https://discourse.nodered.org/t/on-off-ikea-tradfri-with-loxone/74649/6 "2023-02-03T16:05:33Z")

</div>

> [@jkosatko](#):
>
> Invalid value "Lampička Honza" supplied to : TradfriSwitchControlMessage/0: Partial\<{ topic: (Int | Array), payload: TradfriSwitchControlAction }\>/topic: (Int | Array)/0: Int

It looks as if it is complaining about msg.topic, which is shown at the top of your debug 1 node. In the debug output there is no topic. Have a look at the help text for the node and see what the topic is for. It may be that you just need to add `delete msg.topic` in your function.

For the problem with the function not recognising the payload correctly, unfortunately you have not posted an image showing both debug 2 and debug 1 outputs together.

---

<div class="post-metadata">

**Author:** ![jkosatko](https://avatars.discourse-cdn.com/v4/letter/j/b9bd4f/32.png) [@jkosatko](https://discourse.nodered.org/u/jkosatko)\
**Post date:** [3 February 2023 17:26 UTC](https://discourse.nodered.org/t/on-off-ikea-tradfri-with-loxone/74649/7 "2023-02-03T17:26:43Z")

</div>

Thanks!  
I have changed "function" to the "change" to resolve detection issue and added deletion for the msg.topic and it works fine.

---

<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:** [17 February 2023 17:26 UTC](https://discourse.nodered.org/t/on-off-ikea-tradfri-with-loxone/74649/8 "2023-02-17T17:26:56Z")

</div>

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