Set fixed initial values

Hello list,

Devices I created in HA work fine, but their initial state is “Unknown”. Therefore I wrote a shell script that sets all “Unknown” values to something else, like “Clear” for a PIR and “Closed” for a door and 0.000 for a temperature indicator (using mosquitto_pub):

mqtt:
  sensor:
    - name: "ha_temp01"
      state_topic: "home/hbs/ha_temp01"
      device_class: "temperature"
      unit_of_measurement: "°C"
      unique_id: "sensor_ha_temp01_202412081223"
  binary_sensor:
    - name: "pcf PIR BG"
      state_topic: "pcf8574/0x38/5/contact"
      payload_on: "_0"
      payload_off: "_1"
      qos: 0
      device_class: motion
      value_template: "{{ value_json.state }}"

I tried several syntaxes but the validator definitly says “no”. Is there a simple way to add fixed initial values?

R.

Hi Richard,

Make sure what you are changing it ti is valid for the integration or data type. Boolean, number, float, whatever it needs it needs to be valid or you will get ‘unknown’.

You may be better off using a default in a template when you are reading them and let the data stay the data, instead of the data be what you tell it to be. Might bite you somewhere else later.