Toggle binary_sensor with mosquitto_pub [solved]

Hello list,

I have a few temperature meters that I can set with mosquitto_pub, as shown here

Now, I want to add a binary_sensor but apparently I’m missing something crucial somewhere. These are the temperature sensors in configuration.yaml and I added a binary_sensor to it:

mqtt:
  sensor:
    - name: "ha_temp01"
      state_topic: "home/hbs/ha_temp01"
      device_class: "temperature"
      unit_of_measurement: "°C"
      unique_id: "sensor_ha_temp01_202412081223"
    - name: "ha_temp02"
      state_topic: "home/hbs/ha_temp02"
      device_class: "temperature"
      unit_of_measurement: "°C"
      unique_id: "sensor_ha_temp02_202412081355"
  binary_sensor:
    - name: "ha_bool01"
      state_topic: "home/hbs/ha_bool01"
      unique_id: "binary_sensor_ha_bool01_202501011100"
      device_class: "garage_door"

To alter the values of the temperature indicators I run:

mosquitto_pub -h 192.168.64.32 -t home/hbs/ha_temp02 -m "19.3"

That works like a charm. Now, I want to set the boolean to on and off but no way, it keeps saying “state unknown”:

mosquitto_pub -h 192.168.764.32 -t home/hbs/ha_bool01 -m "on"

Anyone a hint?

Richard.

Hi

You need to publish to specific places to auto discover MQTT entities, or in your case for a binary sensor there is this.

Thnx! That helped a lot! I have an old system that reads out I/O expanders PCF8574 and I want the old system report the state changes to HA :slight_smile:

Richard.