MQTT binary sensor not reading value_template payload

I have an automation to control the flow of water into the heating coil in a Hot Water cylinder. The automation opens the valve by energising the relay in a Tasmotized Sonoff Mini when the timer is on and the temperature is below 59C. The valve also has volts free status contacts and I want to read the status of those to control the boiler. The input switch has been disassociated from the relay and if the switch changes state the Sonoff Mini sends an MQTT message e.g. tele/Mini1/SENSOR = { “Time”: “2021-12-04T12:18:51”, “Switch1”: “ON” } which is showing in MQTT Explorer. It is also received by HA and showing in the MQTT Integration Listen to a Topic utility.
My binary_sensor.yaml contains these lines:

- platform: mqtt
  name: "HW2 valve limit switch state"
  state_topic: "tele/Mini1/SENSOR"
  payload_on: "on"
  payload_off: “off”
  qos: 0
  device_class: opening  
  value_template: "{{value_json.switch1}}"
  icon: "mdi:pipe-valve"

The binary sensor is created and reports state as “closed” regardless of payload changes.
Further if I plot the binary sensor on a history graph the text in the bar shows “Closed” on a green background.

I have spent a good few hours on this but given that the MQTT payload is arriving in HA, I don’t know how else to trouble shoot this.

I’m running core-2011.11.5 on RaspPi4/8GB

I have a DIY motion sensor that I use with this template

  - platform: mqtt
    name: "Den Motion"
    state_topic: stat/denmotion/PIR1
    payload_on: "ON"
    payload_off: "OFF"
    device_class: motion

So, maybe this will work for you also?

  - platform: mqtt
    name: "HW2 valve limit switch state"
    state_topic: stat/Mini1/SENSOR
    payload_on: "ON"
    payload_off: "OFF"
    device_class: opening 

Watch your capitalisation. switch1 is not the same as Switch1. Likewise for your payloads.

Also fix the fancy quotes around your payload_off.

It should probably be something like this:

- platform: mqtt
  name: "HW2 valve limit switch state"
  state_topic: "tele/Mini1/SENSOR"
  payload_on: "ON"
  payload_off: "OFF"
  qos: 0
  device_class: opening  
  value_template: "{{value_json.Switch1}}"
  icon: "mdi:pipe-valve"

Thank you.
I think the funny quotes happened in my copy-and-paste.

I have defined a sensor and a binary_sensor in Mqtt. The sensor works oke the binary_sensor doesn’ t respond to the same mqtt published mesagge. see definitions of sensors below.

Has ony one an idea???

mqtt:

Create extra on/off sensor for “easy” automation???

sensor:

  • name: “X10_door_sensor_tst”
    state_topic: “rfxcom2mqtt/devices/0x09D0”

value_template: “{{ value_json.deviceStatus | int(0) }}”

value_template: '{% if value_json.deviceStatus|int(0) > 0 %}on{%else%}off{%endif%}'

value_template: ‘on’

unique_id: "x10_door_sensor_tst"

binary_sensor:

  • name: “X10_door_sensor_bin”
    state_topic: “rfxcom2mqtt/devices/0x09D0”

value_template: “{{ value_json.deviceStatus | int(0) }}”

value_template: ‘{{ is_state_attr(“sensor.0x09d0_battery”,“deviceStatus”,2) }}’

value_template: '{% if value_json.deviceStatus|int(0) > 0 %}on{%else%}off{%endif%}'

value_template: ‘on’

unique_id: "x10_door_sensor_bin"
device_class: garage_door

Really, please, format your code

Each sensor/binary sensor has more than 1 value_template. See the documentation, there can only be one