Hello!
-
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 -
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. -
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! -
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.
-
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!