How to toggle switch via mqtt on another Ha instance

I have multiple HA instances (3), all connected to the central HA mqtt ‘hub’ which runs the MQTT add-on. All runs fine, and I can extract all events on all instances according the setup needs.

I’ve now added an aeonlabs Zwave stick and finally managed to successfully connect it and add several switches to it. I can see the events and see the state and sensors it produces on my other HA instances by way of a mqtt-statestream, in which the streamed events are configured. So far so good.

What I don’t know yet, and seek your help with, is how I can toggle the switches from another instance than the Zwave instance on which these switches are created and visible as switches…

On the other ‘subscribing’ instances the state of these switches is a sensor, and not a switch…

I know of mqtt switches, but they require a command t send to the Zwave hub/switch, and it is that I dont know how to do.

this is the full switch module

and this the switch:

40

dont see a command-topic…

I have other sensors I switch using a command_line curl command, on another Mqtt hub. Don’t see that here either?

Please help and have a look?
Thanks!

Make a MQTT topic that stores an entity_id and a state. Maybe even add a timestamp so HA doesn’t suppress like states.

In your main ha, whenever you want to turn on/off a switch. Populate that topic.

In the zwave ha, monitor that topic with an automation and properly turn_on or turn_off using a service_template and data_template.

A yes, the other way round :wink: of course thats possible too!

in that case I don’t even have to publish the states of the switch do I? Simply publish the new self created topics, and have the state of the real switch be the value_template I would imagine?

Still, there are many of these identical switches in my other Hub, and I can switch these like:

    sw_multi_purpose_cl:
      friendly_name: Multi purpose (cl)
      command_on: >
        curl -X POST -d '{"seq":1, "method":"object_prop_set", "arguments":{"oid":"7b4d9b1b", "prop":"command", "value":"on"}}' http://192.168.1.27/iungo/api_request
      command_off: >
        curl -X POST -d '{"seq":1, "method":"object_prop_set", "arguments":{"oid":"7b4d9b1b", "prop":"command", "value":"off"}}' http://192.168.1.27/iungo/api_request
#      command_state: >
#        curl -X POST -d '{"seq":1, "method":"object_prop_get", "arguments":{"oid":"7b4d9b1b", "prop":"state"}}' http://192.168.1.27/iungo/api_request
      value_template: >
        {{value_json.rv.value == 'on'}}

as you can see there must be some interface between the actual switch (and its states/attributes) and the hub talking over the ‘http://192.168.1.27/iungo/api_request

not sure what that request does (will try to get it from the developers) but somehow I must be able to talk to the switch directly, and not have it listen to another state and switch its state by an automation.

thanks!

zwave is tightly wound into home assistant. I don’t believe this method exists for zwave devices but I could be wrong.

could very well be the other Hub does as you prescribe, and hides that behind the ‘http://192.168.1.27/iungo/api_request’ internally. I’ll see if I can request that info.

for now I have this, and it is working. Silly thing is, it doesn’t use the state topic of the real switch at all…

names No and Double are of course somewhat trifle, but I need that because these are imperfect switches: 1 doenst measure at all anymore, and the other effectively doubles the actual power…

Client side (non hub, so ‘switch’ using input_booleans)

## Zwave mqtt switches across devices
## Client side (input booleans)
##########################################################################################
## Customize
##########################################################################################
#
#homeassistant:
#  customize:

input_boolean:
  everspring_no:
    name: Everspring No
  everspring_double:
    name: Everspring Double

##########################################################################################
## Sensors
##########################################################################################

sensor:
  - platform: mqtt
    name: Everspring double power_state
    state_topic: 'everspring_double_power_state'

  - platform: mqtt
    name: Everspring no state
    state_topic: 'everspring_no_power_state'

##########################################################################################
## Automations
##########################################################################################

automation:

##########################################################################################
# Everspring
##########################################################################################

  - alias: 'Everspring No'
    id: 'Everspring No'
    trigger: 
      platform: state
      entity_id: input_boolean.everspring_no
    action:
      - service: mqtt.publish
        data_template:
          topic: 'everspring_no_power_state'
          retain: true
          payload: >
            {{ states('input_boolean.everspring_no') }}

  - alias: 'Set Everspring No'
    id: 'Set Everspring No'
    trigger:
      platform: state
      entity_id: sensor.everspring_no_power_state
    condition:
      condition: template
      value_template: >
        {{ states('sensor.everspring_no_power_state') in ['on','off'] }}
    action:
      service_template: >
        input_boolean.turn_{{states('sensor.everspring_no_power_state')}}
      entity_id: input_boolean.everspring_no

  - alias: 'Everspring double'
    id: 'Everspring double'
    trigger: 
      platform: state
      entity_id: input_boolean.everspring_double
    action:
      - service: mqtt.publish
        data_template:
          topic: 'everspring_double_power_state'
          retain: true
          payload: >
            {{ states('input_boolean.everspring_double') }}

  - alias: 'Set Everspring double'
    id: 'Set Everspring double'
    trigger:
      platform: state
      entity_id: sensor.everspring_double_power_state
    condition:
      condition: template
      value_template: >
        {{ states('sensor.everspring_double_power_state') in ['on','off'] }}
    action:
      service_template: >
        input_boolean.turn_{{states('sensor.everspring_double_power_state')}}
      entity_id: input_boolean.everspring_double

Zwave hub side (using switches)

## Zwave mqtt switches across devices
## Z-wave hub side (switches)
##########################################################################################
## Customize
##########################################################################################
#
#homeassistant:
#  customize:


##########################################################################################
## Sensors
##########################################################################################

sensor:
  - platform: mqtt
    name: Everspring double power state
    state_topic: 'everspring_double_power_state'

  - platform: mqtt
    name: Everspring no power state
    state_topic: 'everspring_no_power_state'

##########################################################################################
## Automations
##########################################################################################

automation:

##########################################################################################
# Everspring switches
##########################################################################################

  - alias: 'Everspring No'
    id: 'Everspring No'
    trigger: 
      platform: state
      entity_id: switch.everspring_no_power
    action:
      - service: mqtt.publish
        data_template:
          topic: 'everspring_no_power_state'
          retain: true
          payload: >
            {{ states('switch.everspring_no_power') }}

  - alias: 'Set Everspring No'
    id: 'Set Everspring No'
    trigger:
      platform: state
      entity_id: sensor.everspring_no_power_state
    condition:
      condition: template
      value_template: >
        {{ states('sensor.everspring_no_power_state') in ['on','off'] }}
    action:
      - service_template: >
          switch.turn_{{states('sensor.everspring_no_power_state')}}
        entity_id: switch.everspring_no_power
#      - service_template: >
#          input_boolean.turn_{{states('sensor.everspring_no_state')}}
#        entity_id: input_boolean.everspring_no

  - alias: 'Everspring Double'
    id: 'Everspring Double'
    trigger: 
      platform: state
      entity_id: switch.everspring_double_power
    action:
      - service: mqtt.publish
        data_template:
          topic: 'everspring_double_power_state'
          retain: true
          payload: >
            {{ states('switch.everspring_double_power') }}

  - alias: 'Set Everspring double'
    id: 'Set Everspring double'
    trigger:
      platform: state
      entity_id: sensor.everspring_double_power_state
    condition:
      condition: template
      value_template: >
        {{ states('sensor.everspring_double_power_state') in ['on','off'] }}
    action:
      - service_template: >
          switch.turn_{{states('sensor.everspring_double_power_state')}}
        entity_id: switch.everspring_double_power
#      - service_template: >
#          input_boolean.turn_{{states('sensor.everspring_double_state')}}
#        entity_id: input_boolean.everspring_double

little update:

of course I could have used the true switch state on the hub side, but, I would have still needed to subscribe on the client sides sensor for state, so might as well parallellize them on both sides… working just fine now, though it still itches I dont know how to send a command_topic to the switch.