Feeling stupid... How do I automate turning on and off a ZWave switch?

I’m trying to make a simple automation that turns on ZWave switch device id 4 when triggered. And I just can’t figure out how! :persevere: Feel like an idiot, really. I have chosen call_service and switch.turn_on, and in the service data I have:

{
  "node_id": 4
}

But that’s not working. So can somebody please take pity in me?

Also I have a bunch of plugs in the house, and I would very much like not to write a separate automation for each of them. So is it possible to use the payload to choose which switch it should control, somewhat like this:

{
  "node_id": payload
}

This should be what your after.

automation:
  - alias: Turn on zwave switch 15 before sunrise
    trigger:
      - platform: sun
        event: sunrise
        offset: '-00:15:00'
    action:
      - service: homeassistant.turn_on
        entity_id: fibaro_system_fgwpef_wall_plug_switch_1

I’ve used one of my zwave switches as an example.
You don’t trigger the device based on the node_id but instead use the entity_id from Home Assistant.
A list of your devices can be found at http://HAIP:8123/dev-state

I’m a tad confused on what the second part of your question refers to.

We can take the second part later, but first I need to get a working switch. :joy: So here is what I can see under that switch in dev-state:

switch.switch
off value_index: 0
value_id: 72057594109837312
value_instance: 1
friendly_name: TV-bryter
node_id: 4

Is my entity ID just switch.switch? “TV-bryter” means TV switch (for turning of and on power to the TV).

Your device-id in this case i swtich.switch (You can change that in the entity_registry.yaml file).

That works! OK, thanks both of you.

So to the second part:

My main control scripts in EventGhost and Girder sends MQTT to Hass to turn on and off stuff. They go out with a topic like this:

TurnOnSwitch

And then a payload like this

Switch1

or

Switch11

What I would like to have is one automation with MQTT as the trigger, and the same topic, but which takes that identity from the payload. In otther words what switch is turned on is controlled by the payload. That of course means that I have to use the payload as variable and the have a variable in the action.

action:
  - service: homeassistant.turn_on
    entity_id: payload as variable

Is that possible, or do I have to make one automation for each switch, with the payload as the difference in the MQTT trigger?