Add node-red switch to home assisstant

Hi

I have few switchs in node-red but i don’t know how can i add them in home assisstant.
if someone know that.

they are my switchs

and i want add them like that to home assisstant

Hello Vahid_Barz,
I see in your flow that you use MQTT, you could use an MQTT switch, see here:
https://www.home-assistant.io/components/switch.mqtt/
Or what is very interesting, ESPHome, look here in the link:
https://esphome.io/index.html
greetings

i use this code but it doesn’t work !!!
is it something wrong?

- platform: mqtt
  name: "lct"
  command_topic: "lctech/cmd"
  payload_on: "relay,0,1"
  payload_off: "relay,0,0"

Hello, I am not a professional, in your configuration, everything seems to be fine. (Is “switch:” about?) If you stick to the description, there should be no problems. The correct formatting is very important !!! Did you check your configuration and restart your system?

yeah that is switch. i check it and restart raspberry again but it doesn’t work…
i don’t know why

thanks i find problem that was /

- platform: mqtt
  name: "lct"
  command_topic: "/lctech/cmd"
  payload_on: "relay,0,1"
  payload_off: "relay,0,0"

Just out of interest, if you have control over the MQTT topic, best practice is not to start with a “/”. See here for example.

1 Like