Using MQTT topics to call states (node-red automation)

I have given up on automation using the HASS in-built. For now i find it too hard to debug and is too long winded.

my current set-up is using node-red to trigger HASS automations, so for instance i use the “Big Timer” node to trigger a lamp, it then sends an MQTT message to the topic HASS/switch/lamp/ with the value “on” or “off”, then in HASS i have an automation which monitors that topic, and turns the switch on or off.

I would like to use a generic component or automation that will refer to any of my HASS entity, and perform the appropriate action. For Example:

HASS/switch/lamp/, “on” will turn switch.lamp on.
HASS/script/timer/, “on” will turn script.timer off.
HASS/switch/pump/, “toggle” will toggle switch.pump.

Is there a generic way of doing this? the entity is extracted from the topic, and sets the state of that entity to the message?

You might use the entity_id for doing this, it will be like:

action:
service: homeassistant.turn_off
entity_id: switch.eletrovalvula_1

1 Like

Would also like to have a component to send MQTT commands to HASS.

For Example:

HASS/switch/lamp_livingroom/command, “on” (turns on the livingroom light)
HASS/switch/lamp_livingroom/brightness, 80 (turns brightness of the livingroom light to 80)
HASS/switch/lamp_livingroom/rgb_color, [255,0,0] (changes collorof the livingroom light to 80)

1 Like