#Mqtt set vs state

1 messages · Page 1 of 1 (latest)

royal trellis
#

Probably a question that has a very simple answer but here goes:
I'm trying to create a switch for my VPN server that allows me to toggle On/Off and also displays the state as well:

This how my config for the switch:

#
  • name: 'vpn'
    unique_id: vpn
    state_topic: 'vpn/12345/state'
    command_topic: 'vpn/12345/set'
    availability:
    - topic: "vpn/12345/available"
    payload_on: '{"vpn":{"on":1}}'
    payload_off: '{"vpn":{"on":0}}'
    value_template: '{{ value_json.vpn.on }}'
    state_on: 1
    state_off: 0
#

I can change the status on HAS by changing the state from mqtt explorer. If I toggle the switch, I can send a set command but how do I combine that with changing the state as well.

#

The button slides back to the previous state ofter one second.