Boolean from node red to HA

Hello good mornig for everyone.
I’m new to home assistant and I have a problem that I can’t solve.
I’ve gone through the forum trying to figure out what’s going on, but I can’t find a solution.
I have connected an omron plc to node-red, I have installed the library and I can see from node-red the change of state of the variables, which in principle are boolean (when I get it to work I will read other variables).
But I don’t know how to read them as an entity. I have downloaded the node-red companion plugin and created the entity. But no matter what setting you choose, it always appears to be on.
Even though it’s off.
I want the entity to show me what state the variable is in.
Attached screenshots.
Regards, and thank you very much.

You can use the entity node to create a sensor in HA or create a boolean that you turn on/off with call service node.

The entity switch node expects the boolean value to be in msg.enable. Use a change node and move msg.payload.CIO204.12 to msg.payload.

Personally I’m not a big fan of code that creates entities automagically in HA. My preference is to create an MQTT sensor in HA, and have NR send data to it. Assuming you’re already using MQTT elsewhere.

Using the entity node you will also have to deal with HA restarts, where the entity will be unknown until NR sets it again. With MQTT you can just set the ‘retain’ flag, and HA will automatically get updated with the latest value on restart.

Hello good morning, thank you very much for the answers.
I’ll try to see if I can get it.
But I think the option I like the most is to use MQTT. Although I don’t know if it will be very difficult to apply it.
I still don’t use MQTT at all, although I have the broker installed because I want to use it for temperature.
Could you explain to me how to create an MQTT sensor for HA? and be able to collect NR data?
Or tell me where I can find such information?
All the best

Hello, thank you very much for the answer, but while I find out how to do it with mqtt.
Is this what you mean?
All the best

you don’t like it, it stays red.

You will get the same result with a input boolean and call service as the MQTT route.

I don’t know if it is very difficult. But could you explain to me how to do it?
The MQTT broker, I already have it installed and working.
Kind regards

Settings → devices and services → helpers → create helper → Toggle.

Then in Node red add a call service to turn on or off the boolean with the service input_boolean.turn_on or off.

Sorry, I’m not clear.
I have created the helper with the toggle option.
But the node red part is not clear to me.
In which part of the flow do I have to insert the service call? And how do I have to configure it?
I am very new to node-red.
kind regards

Import this and replace the inject with what you had earlier.

[{"id":"0ca1ab45e44ee2ba","type":"inject","z":"66ddc282db66c141","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":220,"y":1120,"wires":[["c305b5be3800e57d"]]},{"id":"c305b5be3800e57d","type":"switch","z":"66ddc282db66c141","name":"","property":"payload.CIO204.12","propertyType":"msg","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","repair":false,"outputs":2,"x":410,"y":1120,"wires":[["91e1dea90c945425"],["6a24bc0441d0dab1"]]},{"id":"91e1dea90c945425","type":"api-call-service","z":"66ddc282db66c141","name":"","server":"4bbca37b.1700ec","version":5,"debugenabled":false,"domain":"input_boolean","service":"turn_on","areaId":[],"deviceId":[],"entityId":["input_boolean.YOUR_BOOLEAN"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":620,"y":1080,"wires":[[]]},{"id":"6a24bc0441d0dab1","type":"api-call-service","z":"66ddc282db66c141","name":"","server":"4bbca37b.1700ec","version":5,"debugenabled":false,"domain":"input_boolean","service":"turn_off","areaId":[],"deviceId":[],"entityId":["input_boolean.YOUR_BOOLEAN"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":620,"y":1160,"wires":[[]]},{"id":"4bbca37b.1700ec","type":"server","name":"Home Assistant","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30}]

just replace the entity in the call service nodes.

hello again.
I really appreciate your effort, but I’m not going to bother you anymore.
Because I am not able to understand what you propose.
The truth is that I don’t know where to go.
I am totally stuck.
kind Regards

If you don’t tell us what problems you have then it’s impossible for us to help.
You had multiple steps to perform from my previous post and your reply is just that you don’t understand.
Understand what?

As said there was multiple steps.

  1. select and copy the json I posted
  2. import the json
  3. replace the inject and reconnect with your existing sequence
  4. change the entity ids in the call service nodes
  5. deploy the flow.

So where are you?
If you don’t put more effort in your problem then I bet nobody else will either.

Hello, I don’t think it’s due to effort, before asking for help I spent a whole week trying to find a solution.
And the answer to what you ask me is very simple.
When I told you that I don’t understand, it’s because I was already stuck at the beginning.
point 2 “import json”.
Import to where? replace injection. what injection?
What flow do I have to use and where?
That’s why I put that I’m totally lost.

This is what you should have said instead of “I don’t understand”

Open the import:

Paste it, and import:

It would be something like this?
In entity identifier I should put a name? or the input number?CIO

I don’t know what you named your input_boolean. You haven’t said that. But I doubt HA accepts a dot in the name.
But whatever you named the input_boolean/toggle helper add this to call service nodes.

But the second image looks correct as far as I can see

So I must be missing something.
Because the input changes state but HA doesn’t know about it.

open a new tab and go to developer tools → states and find the entity and click on the i.

What do you see?