Espurna, mqtt, home assistant

Hi! Could anyone help me with this problem with Espurna and HA.
I have a Sonoff Th16 v2.1 and flashed it with Espurna 1.12.6 and one DS18b20 temperature sensor.
Now the problem is that sensor is showing like switch in HA states and not like sensor, i don´t really know what to change now so i could get sensor temperature in HA, mqtt broker works and i can read temperature in Espurna Web UI. Here is my configuration

Conguration.Yaml

  mqtt:
    broker: 192.186.1.83
    port: 1883
    client_id: home-assistant
    username: my username
    password: my password    
       
  sensor:
    - platform: mqtt
      state_topic: 'tele/Sonoff_TH/SENSOR'
      name: 'Temperature'
      unit_of_measurement: '°C'
      value_template: '{{ value_json.DS18b20.Temperature}}'

In Espurna webui i have in MQTT Root Topic {Sonoff_TH} and MQTT Retain ON
and in General Hostname there is default ESPURNA_3294D5
I´m not really shore if it have to be SENSOR or Temperatur in state_topic or if tele is necessary
and then i´m unsure about value_template:
This is what it shows in HA states [switch.espurna_3294d5]
Would be very happy if someone could help me out on this :slight_smile:

Edit
I reinstalled mosquitto and now it dosn’t show switch anymore but it shows my routers information in states like sent kbyte_sec recieved and sent, this is one of them sensor.dsl_ac68u_kbyte_sec_recieved
It’s like home assistant not reading configuration.yaml mqtt sensor. Do i have wrong code in state_topic and value :thinking:

No one that can help?

If you paste the mqtt messages that are being sent I might be able to help, but I have no experience with espurna, so I can’t tell what might happen from its configuration.

Thanks for your reply! I’m little bit newbie to mqtt so how do i get the mqtt messages :slightly_smiling_face:

You need another client, such as mosquitto_sub or MQTT.FX, to connect to your broker and subscribe to the topic “#” - which means all messages, so the broker will send all message to your client to display

See

Ok thanks. Would this be the right one ```
mosquitto_sub -h 192.168.1.83 -v -t “home-assistant/#” I will soon go and check

Better to subscribe to all topics, unless you miss something

mosquitto_sub -h 192.168.1.83 -v -t “#”

and you may need username and password parameters depending on your broker configuration.

Is this the right one
{Sonoff_TH}/relay/0 0
{Sonoff_TH}/app ESPURNA
{Sonoff_TH}/version 1.12.6
{Sonoff_TH}/board ITEAD_SONOFF_TH
{Sonoff_TH}/host ESPURNA_3294D5
{Sonoff_TH}/ip 192.168.1.93
{Sonoff_TH}/mac “my mac adress”
{Sonoff_TH}/rssi -69
{Sonoff_TH}/uptime 93609
{Sonoff_TH}/datetime 2019-01-27 12:57:45
{Sonoff_TH}/freeheap 22368
{Sonoff_TH}/vcc 3256
{Sonoff_TH}/status 1
{Sonoff_TH}/loadavg 1
{Sonoff_TH}/temperature 21.3

That is it. Your temperature message is coming out as

 {Sonoff_TH}/temperature 21.3

So your sensor should look something like

sensor:
  - platform: mqtt
    name: "Temperature"
    state_topic: "{Sonoff_TH}/temperature"
    unit_of_measurement: '°C'

Now i tryed with that but it´s the same, i only get some routers info. I´m not really sure if i have right name in Espurna MQTT Root Topic, now i have the {Sonoff_TH}

Do you know if things like this would work better with Tasmota, if so is it possible to flash Tasmota with usb2uart or dos it have to be arduino? I tryed with Espeasy but didn’t got any states with that, maby my configuration was wrong.

I have just tried the configuration out on my test system and it works just fine when I send this message

 mosquitto_pub -t "{Sonoff_TH}/temperature" -m 23

which should match what your Espurna is sending, so I don’t see why it wouldn’t work for you.

But if you are having difficulty with this, you might want to try the Tasmota discovery mode, which means you don’t have to set up anything in your yaml file. I have no idea if that would support what you need, as I don’t use it myself.

Okay thanks. But isn’t discovery mode for switches or have i understood something wrong :thinking:
Edit
Seems it was only for autodiscovery on Espurna and Espeasy for switches :slightly_smiling_face:

I got it last to work with Tasmota. I removed mosquitto and used mgtt from home-assistant Webui and then it showed up, dont know if it have to do with that i use Hassbian :slightly_smiling_face: