OpenMQTTGateway MQTT Switch

Hey,

I recently put together an NodeMCU ESP8266 RF Sender/Receiver so that I can control outlets/plugs and listen to RF doorbell.

I used this .bin file to flash the board and the hardware is working well.

However, I cant get the Home Assistant side of things to work as OMG is intended. The MQTT Switch toggles my outlet/plug but the switch wont change state whenever i use the remote - which i think is what is supposed to happen.

I tried state_topic: OMG/OpenMQTTGateway/433toMQTT but i dont think it syncs because when a command is sent this topic changes to just the value (13451403) but if the remote is sent then the state topic is in JSON and i think that might be why the HA switch doesnt sync.

Any help rectifying this would be appreciated.

Thanks

switch:
- platform: mqtt
  name: “Energenie3”
  state_topic: OMG/OpenMQTTGateway/commands/MQTTto433
  command_topic: OMG/OpenMQTTGateway/commands/MQTTto433
  payload_on: 13451403
  payload_off: 13451402
  # optimistic: true
  retain: true
  qos: "0"

image

From: MQTT - Home Assistant

payload must be a string. If you want to send JSON then you need to format/escape it properly. Like:

topic: home-assistant/light/1/state
payload: "{\"Status\":\"off\", \"Data\":\"something\"}"

Hi @tom_l

Sorry but I don’t understand how your post helps me - I’m a not too experienced with coding etc. can you explain what is should do?

Thanks

Getting closer but still not correct.

i changed the switch to include value_template and now the toggle is in sync with the remote but when ask HA to turn the switch ON in the UI is immediately reverts back to OFF

- platform: mqtt
  name: “Energenie3remotesync”
  state_topic: OMG/OpenMQTTGateway/433toMQTT
  command_topic: OMG/OpenMQTTGateway/commands/MQTTto433
  value_template: '{{ value_json.value}}'
  payload_on: 13451403
  payload_off: 13451402
  # state_on: 13451403
  # state_off: 13451402
  # optimistic: true
  retain: true
  qos: "0"

This solution worked in the end. Thanks for your help

switch:
- platform: mqtt
  name: “Energenie 3”
  state_topic: OMG/OpenMQTTGateway/433toMQTT
  command_topic: OMG/OpenMQTTGateway/commands/MQTTto433
  value_template: '{{ value_json.value}}'
  payload_on: '{"value":13451403}'
  payload_off: '{"value":13451402}'
  state_on: 13451403
  state_off: 13451402
  # optimistic: true
  retain: true
  qos: "0"
1 Like