MQTT Problems, weather sensor state always "unknown"

Hello all

I’m trying to inclucde a MobileAlerts weatherstation into my home assistant envorinment.

On my Synology NAS I’m running this script:

{
  "localIPv4Address": "192.168.0.xxx",
  "mqtt": "mqtt://192.168.0.xxx",
  "mqtt_home": "MobileAlerts/", 
  "mqtt_username": "mqtt_alert",
  "mqtt_password": "MY_PASSWORT",

  "logfile": "./MobileAlerts.log",
  "logGatewayInfo": false,

  "proxyServerPort": 8080,

  "mobileAlertsCloudForward": false,

  "serverPost": null,
  "serverPostUser": null,
  "serverPostPassword": null

}

On my home assistant server (a raspberry) I’ve installed MQTT broker with the following configuration:

logins:
  - username: mqtt_alert
    password: MY_PASSWORT
anonymous: false
customize:
  active: false
  folder: MobileAlerts
certfile: fullchain.pem
keyfile: privkey.pem
require_certificate: false

Now, on my NAS i see that the service is running:

### Local IP address for proxy: 192.168.0.172
(node:31664) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
Mobile-Alert Gateway : 001d8c0dffb7
Name                 : MOBILEALERTS-Gateway
Use DHCP             : true
DHCP IP              : 192.168.0.xxx
Fixed IP             : 192.168.1.xxx
DHCP Netmask         : 255.255.255.0
Fixed DNS IP         : 192.168.1.xxx
Fixed Gateway        : 192.168.1.xxx
Use Proxy            : true
Proxy Server Name    : 192.168.0.xxx
Proxy Port           : 8080
Data Server Name     : www.data199.com
### MQTT server is connected
undefined MobileAlerts/035xxc2xxd54d/json {"temperature":[22.4,22.4],"humidity":[63,63],"id":"0x35c27xxxx3d74d","t":"2020-11-03T18:40:58.000Z","offline":false}
undefined MobileAlerts/03xxxxxx6B08A6/json {"temperature":[22.1,22.1],"humidity":[62,62],"id":"03xxxxxx6B08A6","t":"2020-11-03T18:41:15.000Z","offline":false}

Finally, I tried the following configuration (configuration.yaml)

mqtt:
  broker: 192.168.0.xxx
  port: 1883
  username: mqtt_alert
  password: MY_PASSWORD
  
  
sensor:
  - platform: mqtt
    name: "aaa"
    state_topic: "MobileAlerts/03xxxxxx6B08A6/json"
    unit_of_measurement: '°C'
    value_template: "{{value_json.temperature[0]}}"

But, the sensor state remains always “unknown”.

Does somebody see what I did wrong?

Thank you very much for your help and ideas.
Marco

Now, I reinstalled everthing, but still the same…

Have you used MQTT Explorer (http://mqtt-explorer.com/) to see what is actually being received by the MQTT server?

Also why is your sensor path MobileAlerts/03xxxxxx6B08A6/json when I don’t see 03xxxxxx6B08A6 in the NAS service log?

1 Like

Thank you very much for your help.

Sorry about the device ID, I just blurried the code. Now I corrected it, Its the same ID on both sides.

I’ve installed the MQTT Explorer and seeing the msgs:

How do I get this information into my dashboard?

This doesnt work:

mqtt:
  broker: 192.168.0.xxx
  port: 1883
  username: mqtt_alert
  password: MY_PASSWORD
  
  
sensor:
  - platform: mqtt
    name: "aaa"
    state_topic: "MobileAlerts/03xxxxxx6B08A6/json"
    unit_of_measurement: '°C'
    value_template: "{{value_json.temperature[0]}}"

Your sensor looks right, I just tested the template in HA:

{## Imitate available variables: ##}
{% set value_json = {
"temperature":[22.4,22.4],"humidity":[63,63],"id":"0x35c27xxxx3d74d","t":"2020-11-03T18:40:58.000Z","offline":false}
%}

{{value_json.temperature[0]}}

… and I get 22.4 as a string result so now I’m wondering if you have checked to see if HA is actually connected to the MQTT server (any errors in the log?), do you have MQTT configured elsewhere for example in the UI using integrations too? Do you have any other MQTT sensors that work?

1 Like

Thanks for your patience.

No, I don’t have a working MQTT Sensor, now. This is the reason why I think my code is wrong.

I now via Settings -> Integrations -> MQTT -> Config started the listener and it looks like this:

Looks for me like the server is running correctly and is properly connected with HA, isn’t it?

PS: in the Screenshot we’re seeing the Windsensor, without a temperature. But, even if I take a Tempsensor it doesn’t work. The listener was just a test.

I haven’t changed anything, but immediatelly I’m seeing the sensor:

Don’t know why…
I hope it works now, trying to include all the sensors. Will provide e feedback afterwards.

I found my mistake… Embarrassing…

I wrote the hexadecimals in capital letters.
After changing to lowercase it worked without any problems.

Nethertheless, thanks for pushing me into the right direction.