Newb question

I have nodered installed I have what to me seems like a very simple task. I want to create a trigger based on if my govee light is switched and then turn a secondary light on. Same with is the govee light is switched off I want to turn the secondary light off.

I can not figure out how to do this in node red

Also where do the debug messages go I click on them and they do not show anything

I don’t use these node but it looks like the center light node is looking for an entity. Can an entity be set in those center light nodes? The debug messages show up in that right side panel. Set the debug to complete message object.

You can see debug 1 message here

image

Hello!

  1. Welcome to the forum. You may find that reading some of the forum guidelines will help you when you post questions.
    https://community.home-assistant.io/t/welcome-to-the-forum-some-advice/8169

  2. Welcome to Node-RED. Yes, everything in Node-RED is a simple task, until it does not quite work…
    Node-RED (usually as an addon package) is quite a niche subject in Home Assistant, and you will allow others to help you much easier if you post the Node-RED flow (code) as well as pictures. Pictures are nice, but the code is also the configuration of the nodes. Select the nodes, use ‘export’ to clipboard, then use the </> option in the forum edit menu box to open a code block, and post the JSON there.

  3. Where do the debug messages go? Well, they vanish (if you are using Node-RED as an addon) so what you see in the right hand debug window is what you get. Mostly, this is all you need, and the messages you are getting are telling me, mostly, all I need to know.
    You can easily copy a message. Hover over the top of the debug message output below the message header on the right and you will get a ‘copy value / path’ menu - this is great for copying output debug data and can also be posted here too!

  4. You are using the WebSocket nodes. Great! This package of nodes connects back to HA (and you have that working) and can do almost everything you want to do - get entity states, create sensors, call services. That seems to be working too, which is a very good start.

  5. You appear to be trying to use the new Device node. This node carries a great big warning - it is Alpha (so not even Beta) and is very much prototype.
    In short - I don’t think it is working for calling a service. I get the same error as you do. TBH I would not even try to use this node, at this point in time, for doing what you are trying to do.

Home Assistant is based on entities, which include sensors and switches and the like. These entities can belong to a ‘Device’, which is something in HA that, basically, has one or more entities / sensors and perhaps a few services attached to it. For the most part, we use entities when doing anything in HA, and this is reflected in how we do things in Node-RED.

So, I would start with an Events: state node

  • with the entity (the light / switch in question)
  • to test if state is “on”

That is just about all you need, for a trigger to start a flow, when the state value of the entity (light switch) changes to “on” from anything else, and the flow will come out of the top exit (as we have set a condition).

Then I would use a Call Service node to do the switching.

The domain is “switch” and the service is “turn_on” (actually, you can use the “homeassistant” domain which supports turning things on and off, and you may well have another service call provided by your device integration).

The entity is the second switch you want to turn on.

Since all you are doing is turning on and off, your ‘data’ object is not required, so that is it.

As you want to turn the second switch on, and then off, based on just the first switch, we can simplify the flow. Since the Events: state node will trigger from the top exit when the first switch goes ‘on’ and from the bottom exit when the first switch does anything else (‘off’, unavailable) we can use the second exit to turn the second switch ‘off’.

It is possible to simplify further with a bit of JSONata, but you just need to get this working to start with.

Here is my flow - you can copy this and import into Node-RED. I have (best practice) removed the server configuration, so you will have to edit all the nodes to re-connect with your HA server, and you will need to edit the Entity in each. If your integration has provided ‘switches’ with service calls for ‘turn_on’ / ‘turn_off’ / ‘toggle’ you should see all (and only) the entities that can be called with this service in the entity id selector list.

[{"id":"12e40ed423404fb7","type":"server-state-changed","z":"e6f8ea0317d4f26a","name":"","server":"","version":5,"outputs":2,"exposeAsEntityConfig":"","entityId":"switch.t2_2","entityIdType":"exact","outputInitially":false,"stateType":"str","ifState":"on","ifStateType":"str","ifStateOperator":"is","outputOnlyOnStateChange":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":330,"y":3920,"wires":[["27e384e1a86a7cb2"],["d1ce588af50e57c6"]]},{"id":"27e384e1a86a7cb2","type":"api-call-service","z":"e6f8ea0317d4f26a","name":"","server":"","version":5,"debugenabled":false,"domain":"homeassistant","service":"turn_on","areaId":[],"deviceId":[],"entityId":["switch.t3_2"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":620,"y":3880,"wires":[[]]},{"id":"d1ce588af50e57c6","type":"api-call-service","z":"e6f8ea0317d4f26a","name":"","server":"","version":5,"debugenabled":false,"domain":"switch","service":"turn_off","areaId":[],"deviceId":[],"entityId":["switch.t3_2"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":600,"y":3940,"wires":[[]]}]

Good luck with your project.

PS.
Once you get service calls working with entities, then you can experiment with using Device ID. Note that this sends the service call to all the entities associated with a device, or you can use ‘Area’, which does the same for all entities associated with an area. Personally I like to use just ‘entities’ because otherwise I find all the lights in a room going on and off, not just the lamp in the courner!

1 Like

Thank you for the very long detailed reply. That took some effort to type!! Appreciate the help. I will try this later today.

There are many things that I find easier to do in Node Red, but this isn’t one of them. What you are describing is pretty straightforward in Home Assistant automations.

I have a WiFi light switch in the basement and another in the basement stairs. When I turn on either one, both areas are lit. Is this similar to what you want to do?

Yes, essentially I have a govee string light on my gazebo. It has an on/off button. The light output is terrible. So I have a secondary LED strip light that runs on a zigbee controller but no manual switch. I want the govee string light button to turn on/off the LED strip light. So they both turn on/off together.

You aren’t providing much information.
Why do you want to do this in Node Red?
Is your Node Red a stand-alone installation or is it the Home Assistant add-on?
How are you controlling the Govee light string. Node Red or Home Assistant?

No particular reason for doing it in nodered. Nodered is a HA add on. (learning nodered) seemed like any easy one learn how to enable without going off into the weeds.

The Govee string light can be controlled via HA. So can the LED strip light.

I tried in the HA automation and it works 25 second delay from pressing the govee button and the LED strip changing state. It’s slow but it works. Delay is probably associated with the Govee string light just a guess.

When triggering off an entity’s state change the majority of the time you will start with either an event state

image

or a trigger node.

image

Use the light that is switched in an event state, not the button. The top flow will turn on the other light, the bottom will turn it off.

You had the right idea from the get go, you were just using, I won’t say the wrong node but more specialized and mostly untested nodes. The progression is alpha, then beta, then the actual release version.

[{"id":"872aa2c35fc34b88","type":"server-state-changed","z":"0a325c35fc29f44e","name":"use light entity that is switched here","server":"","version":5,"outputs":2,"exposeAsEntityConfig":"011621ce5f7b8be4","entityIdType":"exact","outputInitially":false,"stateType":"str","ifState":"on","ifStateType":"str","ifStateOperator":"is","outputOnlyOnStateChange":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":280,"y":7300,"wires":[["b3921a757cb4cd04"],[]]},{"id":"b3921a757cb4cd04","type":"api-call-service","z":"0a325c35fc29f44e","name":"unswitched light here turn on","server":"","version":5,"debugenabled":false,"domain":"light","service":"turn_on","areaId":[],"deviceId":[],"entityId":[],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":640,"y":7300,"wires":[[]]},{"id":"fdf65062c09414da","type":"server-state-changed","z":"0a325c35fc29f44e","name":"use light entity that is switched here","server":"","version":5,"outputs":2,"exposeAsEntityConfig":"011621ce5f7b8be4","entityIdType":"exact","outputInitially":false,"stateType":"str","ifState":"off","ifStateType":"str","ifStateOperator":"is","outputOnlyOnStateChange":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":280,"y":7400,"wires":[["3ae423156a60b8ee"],[]]},{"id":"3ae423156a60b8ee","type":"api-call-service","z":"0a325c35fc29f44e","name":"unswitched light here turn off","server":"","version":5,"debugenabled":false,"domain":"light","service":"turn_off","areaId":[],"deviceId":[],"entityId":[],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":640,"y":7400,"wires":[[]]},{"id":"011621ce5f7b8be4","type":"ha-entity-config","server":"","deviceConfig":"","name":"exposed as for 011621ce5f7b8be4","version":6,"entityType":"switch","haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"resend":false}]

Thank you for the example. I don’t know why but I was using if boolean=True instead of sting=on did not occur to me to use a string.

The turn on works. But looks like if I set domain=switch the off doesnt work it registers the action but doesnt issue the shut off command

If I switch that bottom one to homeassistant.turn_off of it works fine

Good to know it is working!

The basics of using Node-RED with Home Assistant should be easy, but there are lots of little things that matter.

HA keeps a lot of entity state values as strings, and for the most part avoids using true and false as primitive Boolean values. You will find that integrations support state values as “on” and “off” or “home” and “not home”. Even ‘input_boolean’ switches have state “on” and “off”.

The WebSocket nodes do a lot of work to deal with this for you. The Events: state node (and others) have a ‘State Type’ setting. This pre-processes the state value from whatever it is to what you want it to be, within reason. So strings can be turned into numbers, and also into Boolean. The ‘translation rule’ for this is defined in the configuration server settings, and only applies for these WebSocket nodes. If you look at the configuration nodes, and the homeassistant server, you will find a setting for ‘State boolean’.

This all gets set up for you with Node-RED as an addon, but is usually

y|yes|true|on|home|open

so when the ‘State Type’ is set to ‘boolean’, if the incoming entity state value (string) matches any in the list, it is true, otherwise false. It may seem picky, but there is a difference between “true” and true.

This means that you have options! Use the default string and test for “on” and “off”, or switch to state type ‘Boolean’ and test for true or false. I do find that it is very helpful to be consistent though!

Services do give rise to a great number of questions. Services are added by integrations. When an integration is added to HA it usually adds one or more sensor entities, and some integrations will also add services that can be used (called) to change or update various entities. In general, for any particular entity you need to look at the integration to see what services it provides, and when you select that domain / service combination, HA and the WebSocket node will only provide entities to which that service can be applied in the option selection list.
Somewhere I have an integration that has added ‘switch’, and it works for me on my switch I was using to test my code. Clearly you may not have that integration and service, or you may have ‘switch’ but it works on other entities, or your switches have another ‘govee’ domain under which all the service calls for these devices sit.

That said, Home Assistant comes with a few in-built services out of the box, and has “turn_on” and “turn_off” and “toggle” that will work with anything that, to HA, looks like a switch.

And as an extra:
There was a comment earlier in the discussion suggesting it was easier to do things like this in HA rather than Node-RED. Since you now have this working, here is my minimalist solution, that I submit as being easier than HA automation.

This works, with just two nodes, and almost no settings. The Event: state node has a test condition to check that the (string) state value is in [“on”, “off”], so this will ignore state changes that go to ‘unknown’ or ‘unavailable’, and the usual setting is there to stop the node firing unless the state value has actually changed.

Then, the output properties use a bit of JSONata to set the msg.payload object to run the service call.

{"domain": "homeassistant", "service": "turn_" & $entity().state}

This sets the domain and the service, so nothing has to be set in the Call service node. The service is set to “turn_on” when the entity state value is “on” and “turn_off” when the entity state value is “off”.

The Call service node now only needs the target entity (although you could also set that in the JSONata code as above if you wanted to).

[{"id":"12e40ed423404fb7","type":"server-state-changed","z":"e6f8ea0317d4f26a","name":"","server":"","version":5,"outputs":2,"exposeAsEntityConfig":"","entityId":"switch.t2_2","entityIdType":"exact","outputInitially":false,"stateType":"str","ifState":"[\"on\", \"off\"]","ifStateType":"jsonata","ifStateOperator":"includes","outputOnlyOnStateChange":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"{\"domain\": \"homeassistant\", \"service\": \"turn_\" & $entity().state}","valueType":"jsonata"}],"x":330,"y":3880,"wires":[["a1dc4a4690c7c30f"],[]]},{"id":"a1dc4a4690c7c30f","type":"api-call-service","z":"e6f8ea0317d4f26a","name":"","server":"","version":5,"debugenabled":false,"domain":"","service":"","areaId":[],"deviceId":[],"entityId":["switch.t3_2"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":590,"y":3880,"wires":[[]]}]

The power of using Node-RED is the increased flexibility it brings - this is a very simple case, but the JSONata can be extended to perform more complex conditional testing and to build parameters that would (I submit) be harder to do in Home Assistant.

Enjoy Node-RED!

Thank you for the detailed explanation. My intent here was to learn node red by starting off with something simple. I knew HA could also do the same thing but wanted to learn NR.

Both these solutions work. However I am finding that if the Govee string light loses power (unplugged) and then power is restored both of these fail to reconnect.