Controling gpio pins using node-red and Rhasspy

im stuck at i think the last part in controling the gpio pins whit rhasspy i can’t seem to understand the change node at first i tried using 2 change nodes 1 for on one for off but rhasspy activated both of them at the same time and now im trying to make evrything in just 1 change node but i can’t

Rhasspy sentence :

relay_name = ((LED 1 | LED 2 | relay 3 | relay 4) {name})
relay_state = (on | off) {state}

turn <relay_state> [the] <relay_name>
turn [the] <relay_name> <relay_state>

thank you to anyone who can help me

Hi Red_dragon,

I notice that in the debug window at right of your screenshot:

  1. “debug 1” node appears to be receiving the intent from rhasspy “turn off the LED 1” - which is good. try expanding the “debug 1” entry (by clicking on the right-facing arrowheads) to see the individual fields sent by rhasspy in the slots object
  2. the “LED 1” node is reporting “Invalid input: NaN”, where NaN means Not a Number.

I guess that your change node is setting the GPIO Pin number according to “LED 1” or “LED 2” slot ? Check that it is setting it as a number (0-9), rather than the default string (a-z), like
Screenshot from 2022-08-27 08-31-21

Alternatively open the LED1 node and look for a field which is defined as a number, but you are giving it a string.

I am not using the RasPi GPIO palette or “http In” nodes, so can’t give more detailed instructions from the screen shot you posted. I f still having problem, show us the contents of the change and LED 1 nodes

Hello donburch

What you are saying here is correct. I already tried that and it worked my problem is that the on and off rule must be in the same change node for it to work. Otherwise if i have 1 node for on and 1 node for off rhasspy will activate both of them at the same time. So if i want to turn on the led whit 2 change nodes the led will turn on and then quickly turn off
And i dont undestand why i get the “NaN” problem. I always put the 0g in my number slot.

I hope these are all the things you need for my problem to be more clear to you :smile:

Firstly I would put another debug node after the change node to confirm that it is setting msg.payload as you expect. You are changing msg.state to numeric 0 or 1 - but maybe the last change is converting state back to a string (because of the a-z) before putting it in payload ?

Or maybe the ON | OFF values aren’t even in msg.state ? In the debug panel it looks as though msg contains fields msg.intent, msg.entities, msg.slots, msg.text, and msg.raw_text. I think if you expand the debug 1 node you will find state under msg.slots
Please check out this Node-RED Essentials YouTube video for lots of tips on using the debug panel.

As mentioned before I dont use rpi gpio; but i note that you haven’t selected the “GPIO04 - 7” in the PIN section, but you have entered 4 for “BCM GPIO”. is this because you are not using a Raspberry Pi ?

A different approach might be to use Rhasspy’s sentences.ini to do the work of the change node - check out Substitutions or converters

Im so sorry for this long wait school started and i did not have time to put my head in this problem i did exactly what you said the msg.payload is getting set to state i watched the whole series of videos and i learned a thing or two i use a rassberry idk why in node-red dose not save the node-red change for the GPIO pin

Actually that’s not quite what I said.

You are obviously still learning the basics of nodeRED; and I guess (like me) you are impatient to get the answer to the immediate problem, and so skipping over things that don’t seem to be the answer. I know also from my own experience that it takes a while before things “fall into place” and I see the bigger pattern. Don’t worry, we are all still learning.

There is a lot of very useful information in the Debug panel which you are not seeing. In particular it shows that there is no “state” variable in the msg object; and so your change node is unable to change the value of non-existant msg.state.

As an example, lets take a look at

which simply returns the current status of a power switch with energy monitoring. I have loaded the current state of the entity (on or off) into msg.payload, and the entire entity into

In the debug panel we get a debug node:
You can see that the msg object contains msg._msgid, msg.payload (showing that the switch is currently “on”) and - which is the first level of data - but that is not particularly helpful.

… but expanding all the arrowheads on the left shows that there is a lot more information contained in the msg object

Lets say I am interested in the voltage. Its value is the number (because of no quotes (") around the number) 249.8; but the value named voltage is located in attributes, which is contained in data within msg. Thus the variable is named

debug object heirachy
As a shortcut, when you hover the mouse cursor over the debug window the three buttons will appear, and clicking the “copy path” button saves the variable name which you can easily paste into your code.

And the point of this tutorial ? In your flow, I think if you expand the debug 1 node you will find state under msg.slots. Use the actual variable name in your change node.

okay this time i think i did what you said

can you guide me a little bit more cuz i took the name “on” and “off” “state” pasted them in the change node nohting happend same result as last time im so mad about this beacuse its a sintax error that we are working (more you) for a little 2 months now.

No problem; sometimes we all need a little extra push before the lightbulb goes on :wink:

The debug pane now shows the answer …

We see the current values of state: (“on”) and name: (“Lamp”) have been stored by the Rhasspy node in the slots object, which in turn is stored in the msg object. Looking at the indentation, it is called msg.slots.state;

Thus in the Change node where you now have msg.state you should have msg.slots.state; and you should be setting msg.payload to msg.slots.state, like this:

Note in the debug panel that the value of msg.slots.state has been changed from on to 1, and msg.payload now has the value of 1. This is what you want to see in your own flow.

If the LED still doesn’t go on … well now you know exactly what values are being given to the LED 1 node, and you can take an closer look at what the rpi-gpio out node does.

Hi I did every single thing that you said. I taught it will turn on and then i saw that the value did not change i still get the NaN error for no reason at all

I know that debugging computer systems can be frustrating … so easy to consider the computer as an enemy !
But computers only ever do what they were instructed. In 30 years programming I learnt that it is more like a jigsaw, trying to find the correct size/shape piece to make the picture complete. Most often what we instructed the computer, was not precisely what we wanted. :wink:

  1. Your screen shot doesn’t show msg.slots expanded, so I can’t see if the change instructions worked.

  2. The debug 2 node shows that the value of msg.payload contains “slots.state”, which is not a number and so causes the NaN error in the Lamp node.

  3. In the Change node the last entry is actually setting msg.payload to alphabetic value “slots.state”. Changing the type of the value from alphabetic ( image ) to msg. should fix that.

Such a little thing can make a big difference :wink: and because they are little details, our brain often does not notice them. I wont even guess how many thousand of hours I have spent looking for things like this, or how often a different person sees the problem straight away.

1 Like

Okay now requasting further asistance if i have 2 light bulbs rhasspy will inject the 2 of my change nodes is there any way to stop that from happening ?

Not a problem, we all have to start somewhere.

What do you want to achieve ? One verbal command that turns both bulbs on and off together ? One verbal command where you specify which bulb to turn on/off ? Something else ?

I know the Rhasspy documentation can be a bit hard to follow, and I have found that knowing the right keywords makes google so much more useful.

i want to make one verbal command to turn on a lamp and another verbal command to turn on a relay

and when i type turn on the lamp the lamp and the reley turn on at the same time same when i try tu turn off the lamp

In your previous exercise you were passing in both state and name in msg.slots … but to keep it simple we only considered turning the lamp on/off.

You will need to add a switch to check whether to go to your lamp or Relay node as appropriate. I am confident you can figure our where to put the switch in your flow, and which slot to check.

I knew i had to work whit the switch node so i tried what you said i i did not get it right this is how my flow looks like now and the switch node

That’s a good start … but isn’t msg.slots.state used for the on|off ?

You have already provided all the information you need. Give it some thought, and maybe look in the debug tab at what data is already available … and try again. And if that doesn’t work, try something else.

okay so i tried a lot of conbinations so at this point im just trying to guess it

" You have already provided all the information you need."
that is making me asking more questions
thank you for letting me working by myself but can you give me a push a little keyword something cuz im trying combination’s for 1 hour now

Sigh ! You are not going to get very far by making wild guesses and asking other people to do the work for you. Either you have not made much effort to understand my explanations above; or I am just no good at explaining for you. :sob:

Yes, there is a huge amount to understand; and most of the official documentation is hard to understand. Even with 30 years programming experience I got overwhelmed and gave up on Home Assistant twice before I got it working for me. Google, YouTube, tutorials and discussion forums are easier to understand - but information can get out-of-date quickly. It is up to you to read, watch and try to understand.

I got overwhelmed from the start you are explaing so good to me im just too stupid to understand it i never tought some text from a random person from the internet can make me smile i am just not getting it and i dont want to give up just cuz i can’t understand the switch node i would like to work all by my self but im just not getting the hang of it i dont know if you understood from my typing and stuff but im just a kid logic i am not getting it so fast yes evryone says im a smart kid even teachers even random peple from the street say that but programing is like learning 30 languges at the same time