I don’t often use MQTT and the recent changes that remove configuration.yaml entries have me a bit perplexed.
The project is a remote, battery-powered propane tank sensor. I have the hardware built and the code seems to be working OK to read the value and publish the level via MQTT then go into deep sleep. The sleep values in the code are just for testing, once deployed I anticipate that I will wake the device once a week to report level then back to deep sleep.
Here is my YAML code (excluding all the standard stuff):
deep_sleep:
id: deep_sleep_control
run_duration: 3min
sleep_duration: 2min
mqtt:
broker: 192.168.10.100
port: 1883
username: !secret mqtt_user
password: !secret mqtt_password
discovery: True
discovery_retain: True
client_id: propanemonitor
topic_prefix: propanemonitor
on_message:
- topic: ota_mode
payload: 'ON'
then:
- logger.log: 'OTA Mode ON - Deep sleep DISABLED'
- deep_sleep.prevent: deep_sleep_control
- topic: ota_mode
payload: 'OFF'
then:
- logger.log: 'OTA Mode OFF - Deep sleep ENABLED'
- deep_sleep.enter: deep_sleep_control
sensor:
- platform: adc
pin: A0
name: "Propane Sensor"
update_interval: 2min
filters:
- multiply: 3.3
- lambda: return x * (31.66360585143436) + (10);
unit_of_measurement: "%"
The problem is that the device is waking, publishing the value (which I can see in my MQTT client) but the sensor is not updating in HA and when the device sleeps, it changes to ‘Unavailable’.
I have followed some of the other posts on here and I figure that the sensor needs ‘force_update’ as the value is not changing during testing but with the MQTT changes in HA, I cannot for the life of me, figure out how to do that. I’ve tried adding the code to my sensors.yaml file but the config check complains that it now needs to be done in the integration. I cant see a way to add it in the integration.
The message does seem to have the retain flag set…
Any suggestions?