MQTT Configuration for Controlling Physical Switch

Hello, I have a ZWave switch that I am trying to connect to MQTT to have it send On/Off Commands to Mosquitto and in return receive On/Off Commands from another platform via MQTT. I have it publishing via MQTT but am unclear if I have to make another automation to also receive commands back or can somehow combine the two?

I appreciate any help you can provide.

This is what I have so far:

- id: '1590942737754'
  alias: MQTT-Switch-Office-On
  description: ''
  trigger:
  - entity_id: light.act_unknown_type_4457_id_3230_level
    platform: state
    to: 'on'
  condition: []
  action:
  - data:
      state_topic: homeassistant/switch/office/state
      command_topic: homeassistant/switch/office/command
    service: mqtt.publish
- id: '1590949077643'
  alias: MQTT-Switch-Office-Off
  description: ''
  trigger:
  - entity_id: light.act_unknown_type_4457_id_3230_level
    platform: state
    to: 'off'
  condition: []
  action:
  - data:
      state_topic: homeassistant/switch/office/state
      command_topic: homeassistant/switch/office/command
    service: mqtt.publish

I’m surprised to hear that because the way your automation calls the mqtt.publish service doesn’t correspond to anything in its documentation:

The minimum requirement to publish something are topic and payload yet your automation specifies neither of them.


I suggest you consider implementing the solution in the following post. Someone had a similar requirement (two instances of Home Assistant; need to control a light on one instance from the other instance) I offered a solution that employed MQTT Statestream and an automation.


NOTE
If you wish to share many entities then you may be better off using this custom integration:

Thanks so much for the information, it helped out.

One other question that is probably not related to mqtt but when I turn off a zwave switch in homeassistant the switch toggles off, then back on in the interface. However, the light does turn off. When I hit off again, the switch stays off in the interface and of course the light does nothing since its already off. I tried adding the following to my configuration, but it did not seem to help to make the switch properly stay off the first time.

zwave:
  device_config_glob:
    "zwave.switch*":
      refresh_value: true
      polling_intensity: 1

That behavior is typically associated with this: no feedback from the device.

Home Assistant transmitted an off command to the zwave light. It expected to receive a timely reply from the light that its status is now off. However it didn’t get the expected reply so it moved the switch (in the UI) back to the on position.

The challenge is to determine why the zwave light isn’t replying with its status.