[HOWTO] Shelly (stock firmware), MQTT and momentary buttons for on and off

Hello all,

I am using a 2 x Shelly 1’s for my electric fireplace, which requires a momentary button for ‘on’ and one for ‘off’.

I wanted to post my configuration, since it was very painful to do. The keys: switch_template; input_boolean; retain=false.

#Create input boolean to track state
input_boolean:
  fireplace_state:
    name: State of the fireplace
    initial: off
    icon: mdi:fireplace

# Create switches for fireplace
switch:
  - platform: mqtt
    name: "fireplace on switch"
    icon: mdi:fireplace
    command_topic: "shellies/shelly1-on/relay/0/command"
    state_topic: "shellies/shelly1-on/relay/0"
    qos: 1
    payload_on: "on"
    payload_off: "off"
    retain: false

  - platform: mqtt
    name: "fireplace off switch"
    icon: mdi:fireplace-off
    command_topic: "shellies/shelly1-off/relay/0/command"
    state_topic: "shellies/shelly1-off/relay/0"
    qos: 1
    payload_on: "on"
    payload_off: "off"
    retain: false

  - platform: template
    switches:
      fireplace:
        value_template: "{{ is_state('input_boolean.fireplace_state', 'on') }}"
        turn_on:
          - service: switch.turn_on
            data:
              entity_id: switch.fireplace_on_switch
          - service: input_boolean.turn_on
            data:
              entity_id: input_boolean.fireplace_state
        turn_off:
          - service: switch.turn_on
            data:
              entity_id: switch.fireplace_off_switch
          - service: input_boolean.turn_off
            data:
              entity_id: input_boolean.fireplace_state
        icon_template: >-
          {% if is_state('input_boolean.fireplace_state', 'on') %}
            mdi:fireplace
          {% else %}
            mdi:fireplace-off
          {% endif %}

I hope this helps!

tarek : )

1 Like

Thanks Tarek for writing that up. I was having an issue with a template for my fireplace because the Zigbee board I was using is in momentary mode and telling the template switch to turnoff from the first switch toggle action. Using the input_boolean did the trick!

1 Like