Home Assistant switch with MQTT

Hello I got Node-red dashboard and everything works, but I don’t know how to convert node-red nodes to home assistant node. I just wanna do a simple switch in home assistant.
I got switch node (On payload: 1, Off payload: 0) and mqtt out node


how to convert this to Home assistant switch and add it to interface? Thank you. I hope you relate, im just a newbie :smiley:
edit: Do I have to do a custom entity to control the switch?

Install node-red-contrib-home-assistant-websocket from you node pallet, and use the entity node to make the switch. Configure the HA server settings and switch domain/names in the node

Would you please tell me how to configure it? Or link a video? :slight_smile:

When you install the node-red-contrib-home-assistant-websocket, it adds a bunch of nodes to the left panel. Drag the one called “entity” into your flow. Double click on it, from that properties box click on the add new server (unless you already have a Home-assistant server showing in that box). Complete the set-up of the server based on your system, i.e. if you are using the homeassistant add-on, or need a an access token, like mine I’m on core, so no add-ons, like this(token obscured):


Then click update, now select the check box that says sensor, select switch, add the details for the switch you want in HA,

save and restart the flow. There should now be a switch in HA entities, id name based on the name you chose. Hope this helps, you may need to read a bit.

The problem is that I did it before and it doesn’t show anything when I want to add something to my interface. I just name it Switch1 and nothing appears in the interface editor:


Flow

Have you installed the Node red Integration as noted?

image
Yes
edit1: previosuly I got button deploy nodes to home assistant next to Deploy button, but not it doesn’t appear

No, what you are showing is the node pallet in node red. You also need to install the integration in home assistant, Configuration . Integrations > Add integration, search for Node-red companion and install.


can’t find it. I think i got to follow this guide in github: https://github.com/zachowj/hass-node-red

Ok I’ve installed he node-red companion and got the entity:



in entity node I got to turn on “output on state change” and the payload should be $entity().state ? 1: 0 ??

it doesn’t work ;/ on debug when I click button in HA’s Interface (Virtual machine) it sends 1 and 0 as a number like on my other ocal node-red server (not the HAOS on Virtual machine))and there everything works, but here on HAOS VM I don’t know what is wrong ;/

I think you want to put the “switches” entity in your UI. Look for an entity id like switch.switches, and put it in an entity card. Then try to toggle that and see what shows in the node-red debug. I am not sure you need to set anything for output on state change, HA should take care of it.