Alexa Node Red to Viera TV

#1

Hi,

Hoping I can get your help with a simple issue. I have a configured both Alexa and Viera (node-red add-ons) and want to use Alexa to change the volume of my tv.

I know I need the value "bri" but this needs to be sent as a string to the Viera add on. For the life of me, I can't figure out how to send this as a string.

I think one major issue is that the debug request only accepts an object so this means it's very hard to test.

I have exported my config here.

The payload back from alexa for the TV Tv node is:

Blockquote
msg : Object
object
on: true
bri: 3
from: "::ffff:10.0.0.x"
on_off_command: false
payload: "on"
change_direction: 0
bri_normalized: 0.03
device_name: "TV"
light_id: "cd9510e8e8e1f"
port: 41455
_msgid: "cb14f4b3.94ffd8"

the payload from a standard volume inject is:

Blockquote
msg : Object
object
_msgid: "9b6a5a50.2914a8"
topic: ""
payload: "10"

Flow

Blockquote
[{"id":"b7e668ac.002358","type":"viera write","z":"886ce33a.5e652","name":"setVolume","host":"10.0.0.x","function":"setVolume","x":730,"y":100,"wires":},{"id":"dc6fc9be.67ab18","type":"alexa-local","z":"886ce33a.5e652","devicename":"TV","inputtrigger":false,"x":230,"y":120,"wires":[["ffb17ab2.450068"]]},{"id":"7afcb8af.05aa18","type":"debug","z":"886ce33a.5e652","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":730,"y":140,"wires":},{"id":"ffb17ab2.450068","type":"function","z":"886ce33a.5e652","name":"","func":"return msg.payload[0].bri;","outputs":1,"noerr":0,"x":430,"y":140,"wires":[["7afcb8af.05aa18","b7e668ac.002358"]]}]

I have tried, in a function

1:
msg.payload = msg.payload[0].bri;
return msg.payload;

2:
msg.payload = msg.payload.bri
return msg.payload;

3:
return msg.payload[0].bri;

Example TV config that works comes from:

0 Likes

#3

Well I solved it, seems it will accept a number type as well. If some can still help with converting to string, I thing that will be helpful later on.

[{"id":"b7e668ac.002358","type":"viera write","z":"886ce33a.5e652","name":"setVolume","host":"10.0.0.x","function":"setVolume","x":730,"y":220,"wires":[]},{"id":"dc6fc9be.67ab18","type":"alexa-local","z":"886ce33a.5e652","devicename":"TV","inputtrigger":false,"x":230,"y":120,"wires":[["dd75f9a5.cb9698"]]},{"id":"7afcb8af.05aa18","type":"debug","z":"886ce33a.5e652","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":730,"y":260,"wires":[]},{"id":"dd75f9a5.cb9698","type":"change","z":"886ce33a.5e652","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"bri","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":420,"y":120,"wires":[["7afcb8af.05aa18","b7e668ac.002358"]]}]viera3

0 Likes

#4

Glad you got it working one thing to note: When using a function you need to return an object

eg

return msg

rather than

return msg.payload

0 Likes

#5

Thanks,

I think I have the correct code now, returns a string.

Blockquote
msg.payload = String(msg.bri);
return msg;

The key here was to keep the payload object intact.

0 Likes