Generic Temperature Sensor ESP8266

What an amazing job you have done Nymea , I love it !!!
Please I want to read temperature from ESP8266 using Tasmota . I have done all the setting , Generic Temperature Sensor and Internal Mqtt Client .So far I can read the temperature in the Incoming Events but I do not know how to write the script in the magic . This is what the I read in the console when the ESP8266 sent data :

MQTT event reveived: {“27ec8baf-0c13-4d0a-aaee-313582592695”:“d4eca3085b184629b882729347acab3f/sonoff/SENSOR”,“8af98566-79d9-4e65-b1dc-9067e4f93af1”:"{“Time”:“2021-06-28T06:35:32”,“DS18B20”:{“Id”:“3C01D60710A2”,“Temperature”:31.6},“TempUnit”:“C”}",“data”:"{“Time”:“2021-06-28T06:35:32”,“DS18B20”:{“Id”:“3C01D60710A2”,“Temperature”:31.6},“TempUnit”:“C”}",“topic”:“d4eca3085b184629b882729347acab3f/sonoff/SENSOR”}

Hi @pythontest112233

Below is a copy of my script to extract the temperature from a Tasmota ESP8266 device and populate a generic temperature sensor thing:

Item {
    ThingEvent {
    thingId: "{4f53c27c-0170-4107-b533-ad10bb812638}" // DHT11GW
    eventName: "triggered"
    onTriggered: {
       var topicVal = params["data"];
       var temperatureVal = JSON.parse(topicVal);
       temperature1.value = (1.0 * temperatureVal.DHT11.Temperature + 20) / 70 
        }
    }
    
    ThingState {
    id:  temperature1
    thingId: "{47b6c37d-5dae-41ce-91ec-5223d0802ee1}" // Front Room Temperature
    stateName: "input"
    }
    
}

If you paste it into your script you can modify it as follows:

The first section i.e. ThingEvent triggers when it receives data on the MQTT topic.

Backspace out the line that ends with DHT11GW until you reach the first " mark and a drop down will appear. Here you can select the name of your internal MQTT thing.

The first variable topicVal stores the MQTT data.

The 2nd variable temperatureVal parses the MQTT data so that you can extract the temperature value - “temperatureVal.DHT11.Temperature”. You will need to change this to - temperatureVal.DS18B20.Temperature

The last line creates a value to pass to the Generic Temperature thing but also has to convert it into Celsius and uses the min/max values set in the generic thing.

Backspace out the line that ends with Front Room Temperature and insert your generic temperature thing. Hopefully it will start to populate with data. If you want to test it with lots of data type Teleperiod 10 in the Tasmota console to start receiving data every 10 seconds.

Feel free to change the variable names.

1 Like

Perfect ! it works , thank you so much !
Please tell me why from my Ubuntu laptop I can see the temperature in Celsius and from Android app in Fahrenheit ?

App Settings → Look and feel → Unit system

It should detect the preferred one from the platform, for some reason your systems produce different results it seems.

Done ! all in celsius now , thank you !