MQTT - problem parsing date

Hi,

I have an app for water softener running in AppDemon that is publishing a payload for a topic (ecowater/out_of_salt) that looks like a date value.

But the following configuration is ending up with a sensor with “unknown” value for state.

sensor:
  - platform: mqtt
    name: Ecowater Out of Salt Date
    state_topic: "ecowater/out_of_salt"
    device_class: date

What is wrong with above config and is there a way to fix the value?
Thanks.

try to ensure that date is in format YYYY-MM-DD.
The best way would be to change published format (tbh I have no idea why it’s published in local format). If impossible then you probably have to use template mqtt sensor to reparse incomming date value

Does it return a value if you just delete this line?

After removing the line for device_class, I am still getting “unknown” for the sensor (after a restart). So seems like the main issue here is importing the value “03/17/2022” into the state.

Are you able to extract any other part of the MQTT message as a sensor?

sensor:
  - platform: mqtt
    name: Ecowater Out of Salt Days
    state_topic: "ecowater/out_of_salt_days"

Would this generate a result or unknown again? Perhaps you need to use a value template.

I am able to get all payloads from other topics and also able to display information in UI except these two:

  1. out_of_salt: this one seems to be passing a string that looks like date
  2. recharge: this one is passing a list object with HTML tags that HA is not able to handle

For both the above sensors I get “unknown” for state. Seems like fixing the python script under AppDaemon might be an easier option, this is the script I am using - Scrape your ecowater data. https://gnulnx.net/2020/02/18/ecowater-api-scraping/ · GitHub

can you express the mqtt the way mqtt explorer does e.g.
{“message”:{“id”:107,“channel”:0,“battery”:1,“temperature”:7.3,“humidity”:76},“protocol”:“nexus”,“length”:“107”,“value”:“107”,“repeats”:2,“status”:2}
It might give a clue how to extract the date using a value template.

Here is the screenshot from MQTT Explorer:

When I copy using the button in MQTT Explorer then I get value as:

03/11/2022

What about making it a text sensor

@Spiro, thanks but setting up sensor as shown above is giving following error:

Package ecowater setup failed. Component text_sensor Integration 'text_sensor' not found.

And I do not see any option for text_sensor under MQTT integration either, all the examples for “text_sensor” for HA seems to be related to ESPHome.

I am thinking of doing following:

  1. Tweak the python script in App Daemon to post the entire JSON object on MQTT, currently it is parsing attributes and then posting to multiple topics.
  2. Parse the JSON object with HA and hoping to have better luck

That sounds like the best idea if you can get it to work. Good luck with it.

The screenshot of MQTT Explorer shows that the payload published to ecowater/out_of_salt is not a retained message (i.e. it’s not stored on the MQTT Broker). That means every time you modify the sensor’s YAML configuration and execute Reload MQTT Entities, the newly revised MQTT Sensor gets no value from the broker and so it reports unknown. It must wait until the source of the data publishes another payload to ecowater/out_of_salt in order to receive it.

How often does the data’s source publish a new payload to ecowater/out_of_salt?

1 Like

@123 yes adding “retain=true” did the trick and the values are coming into HA!! :sunglasses:

Thanks @Spiro & @maxym :+1: