How to force a template sensor to update even if the value hasn't changed?

I have a bunch of template sensors which listen for MQTT messages:

- platform: mqtt
  state_topic: "bs440/person1/"
  unique_id: bs440_person_1_weight
  name: "Stefan weight"
  unit_of_measurement: "kg"
  value_template: '{{ value_json.weight }}'
- platform: mqtt
  state_topic: "bs440/person1/"
  unique_id: bs440_person_1_body_water
  name: "Stefan body water"
  unit_of_measurement: "%"
  value_template: '{{ value_json.tbw }}'
- platform: mqtt
  state_topic: "bs440/person1/"
  unique_id: bs440_person_1_body_fat
  name: "Stefan body fat"
  unit_of_measurement: "%"
  value_template: '{{ value_json.fat }}'
- platform: mqtt
  state_topic: "bs440/person1/"
  unique_id: bs440_person_1_muscle_mass
  name: "Stefan muscle mass"
  unit_of_measurement: "%"
  value_template: '{{ value_json.muscle }}'
- platform: mqtt
  state_topic: "bs440/person1/"
  unique_id: bs440_person_1_kcal
  name: "Stefan BMR"
  unit_of_measurement: "kcal"
  value_template: '{{ value_json.kcal }}'
- platform: mqtt
  state_topic: "bs440/person1/"
  unique_id: bs440_person_1_bone_mass
  name: "Stefan bone mass"
  unit_of_measurement: "kg"
  value_template: '{{ value_json.bone }}'  

My problem is that the sensors only update if they receive a new value which screws my automation which switches the apartment into day mode as soon as my bathroom scale sends its results. Also, if the scale sends the same value, the value is not written to InfluxDB.

Is there a way inside of HA to force the sensor to update even if the received value is the same?

Just add force_update: true to each and every sensor like this.

- platform: mqtt
  state_topic: "bs440/person1/"
  unique_id: bs440_person_1_weight
  name: "Stefan weight"
  unit_of_measurement: "kg"
  force_update: true
  value_template: '{{ value_json.weight }}'``
1 Like

Ouch, that was obvious! :flushed: Maybe I should have read not only the template sensor docs… Thanks for helping!

1 Like