MQTT Sensor Update

I have a couple of MQTT sensors that that the MQTT value may only change once a week and im using templating to give me a difference in days.
The issue is HA is not recalculating. I guess its because there’s no new MQTT message being published?


      - platform: mqtt
        name: Backup State Janet
        state_topic: 'backup/sensor/janet'
        value_template: "{{ ((as_timestamp(now()) - as_timestamp(value_json.backupTimestamp)) / 86400) | round(2) }}"
        force_update: true
        unit_of_measurement: 'Days'
        json_attributes_topic: 'backup/sensor/janet'

Is there a sensible way of forcing HA to recalculate days? The only workaround can think of is to grab the MQTT data and publish it again but feel like I may be missing something simpler.

Wouldn’t it perform the calculation only when it receives a message published to backup/sensor/janet? If the message arrives once a week, the calculation will only happen once a week.

Or are you saying it doesn’t perform the calculation even when it receives a new message?

No it preforms the calculation when HA is restarted or the MQTT message is received. Which I guess is how its supposed to work.

Yup! Effectively, the sensor’s value won’t change until the receipt of the next payload (a week later; or upon rebooting but hopefully that’s infrequent and not a requirement of daily operations).

The message is retained so I guess I use node red or an automation to read the data or sensor and republish it just after midnight everyday.

Thanks for your help

Update in case anyone else trips over this post.
I have worked out the best way (for me anyway) was a Node Red flow to read the sensor attributes and use them to publish a new MQTT message. This is scheduled to run every 6 hours