ESP8266 - DS18B20 -Generic Sensor - Generic Thermostat

Hi , I use ESP8266 with DS18b20 and I can read the temperature via Generic Temperature Sensor . Is it possible to ON-OFF a relay to another ESP8266 using a the Generic Thermostat ?
Thanks !

Yes, that should be possible. The generic thermostat has an input for the sensor, and two outputs for relays, one for heating, one for cooling. It should work just the same as with the temp sensor.

Maybe I didn’t get the question properly, what exactly is it you’re struggling with?

I do not know how to set up at all . I see in the thermostat settings " Connect Temperature sensor input to " and I choose Generic Thermostat and Target temperature because this is the only options I have . I don not understand what is this

Right… So, you’ve set up the temperature sensor like here, right?

It would be the same more or less for the generic thermostat:

Item {
    // Same as with the generic temp sensor, you'll read stuff from MQTT 
    ThingEvent {
        thingId: "..." // MQTT client with topic filter for the temp sensor
        eventName: "triggered"
        onTriggered: {
           var topicVal = params["data"];
           var temperatureVal = JSON.parse(topicVal);
           thermostatTemp.value = (1.0 * temperatureVal.DHT11.Temperature + 20) / 70 
        }
    }
    
    // But instead of feeding it into a generic temp sensor, you'll feed it into a generic thermostat
    // (you can also feed stuff into multiple generic things if you want) 
    ThingState {
        id:  thermostatTemp
        thingId: "..." // Generic thermostat
        stateName: "temperature"
    }

    // Now watch the "heatingOn" state of the generic thermostat
    // You could repeat this for "coolingON" if you wanna build a fully fledged AC
     ThingState {
        id: thermostatHeating
        thingId: "..." // Generic thermostat, same as above
        stateName: "heatingOn"
        onValueChanged: {
           // Whenever the heatingOn value changes in the thermostat, post the command to control the relay on MQTT
           var payloadValue = thermostatHeating.value == true ? "ON" : "OFF"
           relayControl.execute({topic: "/whatever/topic/you/need", data: payloadValue})
        }
     }
    
    // Now all we need is an Action to post something back to MQTT
    ThingAction {
        id: relayControl
        thingId: "..." // MQTT client posting to Relay
        actionName: "trigger"
    }
}

Note that I just typed this by memory without actually testing it. So plain copy/paste might contain errors… Just write it yourself using the auto-completion of the script editor and you should be good to go.

ok I will try now and let you know

Can I ask you please why I can data if the topic filter is with # only . When I try to add a topic filter removing the # does not work . I delete the # and I write /example/temp1 as a topic filter to MQTT Broker and to MQTT Client and to Internal MQTT .

I want to use many ESP8266 temperature sensors and the probem is that I can see 2 temperatures in the same Internal MQTT

That’s how mqtt works. # is a wildcard. If the topic filter is for example /test/# then it would match /test/abc and /test/abc/def and so on. Without the # it will match only exactly the same topic as the filter.

It’s a bit like *, except it matches even more. A filter of /test/* would match /test/abc but not /test/abc/def.

There sure is something different between the two, no? Something in the topic that allows you to distinguish them.

I use 2 ESP8266 with Tasmota .From the tasmotiser I set up the first one as 192.168.0.200 port 1883 and the second one as 192.168.0.200 port 1884. The ip of the raspberry pi is 192.168.0.200 . So I can see every 10sec the first temperature and after 10 sec the second temperature

You can open the tasmota Webinterface on them and change the topic. Make it a bit different for each of them (perhaps adding a number, or some other name) then you can do

if (topic == "/topic/of/1") {
    console.log("first sensor")
} else {
    console.log("second sensor")
}

in the nymea script

10: MQTT event reveived: {“a947a277-a17a-4cb2-addb-f8ecec1cc63c”:"{“Time”:“2021-07-11T09:33:06”,“Uptime”:“0T00:16:22”,“UptimeSec”:982,“Heap”:26,“SleepMode”:“Dynamic”,“Sleep”:50,“LoadAvg”:19,“MqttCount”:3,“POWER1”:“OFF”,“POWER2”:“OFF”,“Wifi”:{“AP”:1,“SSId”:“Mikrotik1”,“BSSId”:“08:55:31:A3:8B:FC”,“Channel”:5,“Mode”:“11n”,“RSSI”:100,“Signal”:-41,“LinkCount”:1,“Downtime”:“0T00:00:04”}}",“bd83c7ec-3a14-46c6-a064-25757ceb0207”:“tasmota1/STATE”,“data”:"{“Time”:“2021-07-11T09:33:06”,“Uptime”:“0T00:16:22”,“UptimeSec”:982,“Heap”:26,“SleepMode”:“Dynamic”,“Sleep”:50,“LoadAvg”:19,“MqttCount”:3,“POWER1”:“OFF”,“POWER2”:“OFF”,“Wifi”:{“AP”:1,“SSId”:“Mikrotik1”,“BSSId”:“08:55:31:A3:8B:FC”,“Channel”:5,“Mode”:“11n”,“RSSI”:100,“Signal”:-41,“LinkCount”:1,“Downtime”:“0T00:00:04”}}",“topic”:“tasmota1/STATE”}

this is the data in the console for ESP8266 with tasmota topic “tasmota1”

10: MQTT event reveived: {“a947a277-a17a-4cb2-addb-f8ecec1cc63c”:"{“Time”:“2021-07-11T09:46:36”,“Uptime”:“0T00:02:42”,“UptimeSec”:162,“Heap”:26,“SleepMode”:“Dynamic”,“Sleep”:50,“LoadAvg”:19,“MqttCount”:1,“Wifi”:{“AP”:1,“SSId”:“Mikrotik1”,“BSSId”:“08:55:31:A3:8B:FC”,“Channel”:5,“Mode”:“11n”,“RSSI”:100,“Signal”:-47,“LinkCount”:1,“Downtime”:“0T00:00:04”}}",“bd83c7ec-3a14-46c6-a064-25757ceb0207”:“tasmota2/STATE”,“data”:"{“Time”:“2021-07-11T09:46:36”,“Uptime”:“0T00:02:42”,“UptimeSec”:162,“Heap”:26,“SleepMode”:“Dynamic”,“Sleep”:50,“LoadAvg”:19,“MqttCount”:1,“Wifi”:{“AP”:1,“SSId”:“Mikrotik1”,“BSSId”:“08:55:31:A3:8B:FC”,“Channel”:5,“Mode”:“11n”,“RSSI”:100,“Signal”:-47,“LinkCount”:1,“Downtime”:“0T00:00:04”}}",“topic”:“tasmota2/STATE”}

this is the second esp8266 with tasota topic “tasmota2”

import QtQuick 2.0
import nymea 1.0

Item {
ThingEvent {
thingId: “{cb4b008e-8d72-4755-adaa-bcb47bd867da}” // mqtt
eventName: “triggered”
onTriggered: {
var topicVal = params[“data”];
var temperatureVal = JSON.parse(topicVal);
var tasmota1 = JSON.parse(tasmota1);
temp1.value = (1.0 * temperatureVal.DS18B20.Temperature + 20) / 70
}
}

ThingState {
id:  temp1
thingId: "{2375b7d6-6a72-4d62-8851-38516673fe99}" // generic Temperature
stateName: "input"
}

}

and with this script I can see the temperature in the generic temperature sensor .
The problem is that I can see two temperatures in the same generic sensor. The port for the first tasmota is 1887 and for the second tasmota 1888 but does not separate the temperatures . Can you help me please with the script so I can use two different generic sensors ?
Thank you !

import QtQuick 2.0
import nymea 1.0

Item {
ThingEvent {
thingId: “{cb4b008e-8d72-4755-adaa-bcb47bd867da}” // mqtt
eventName: “triggered”
onTriggered: {
var topicVal = params[“data”];
var temperatureVal = JSON.parse(topicVal);
temp1.value = (1.0 * temperatureVal.DS18B20.Temperature + 20) / 70
}
}

ThingState {
id:  temp1
thingId: "{2375b7d6-6a72-4d62-8851-38516673fe99}" // generic Temperature
stateName: "input"
}

}

Sorry , this is the correct script

You’ll need 2 different ThingState objects in the script:

ThingState {
  id: temp1
  thingId: "..." // ID of first generic temp sensor
  stateName: "input"
}

ThingState {
  id: temp2
  thingId: "..." // ID of the second generic temp sensor
  stateName: "input"
}

Then, where the MQTT message comes in, you can do temp1.value = ... or temp2.value = ... depending on which one it is.

thank you , I will try it now

Hi , this is the setup .
Please can you help me with the script or with Mqtt of the tasmota ? I can read the temperature in the generic temperature sensor but I do not know how to use many generic temperature sensors with many tasmota ESP8266 .I read all the temperatures in the same generic temperature sensor.
Please I do not know how to write the script .
Thank you

Item {
    ThingEvent {
        thingId: "..." // MQTT client
        eventName: "triggered"
        onTriggered: {
            var topic = params["topic"]
            var data = JSON.parse(params["data"])

            if (topic == "tele/tasmota_25A589/SENSOR") {
                genericSensor1.value = data.DS18B20.Temperature
            } else if (topic == "tele/tasmota_621EE/SENSOR") {
                genericSensor2.value = data.DS18B20.Temperature
            }
        }
    }

    ThingState {
        id: genericSensor1
        thingId: "..." // ID of first generic temp sensor
        stateName: "input"
    }

    ThingState {
        id: genericSensor2
        thingId: "..." // ID of second generic temp sensor
        stateName: "input"
    }
}

thank you so much for your help :pray:

1 Like