Sonoff TH16 - Comparing temperature probes

I have two Sonoff TH16’s… these measure temperature and display it in the ewelink app.
I also have a smart switch which will turn a diverter left or right depending on if the smart switch is on or off.
The diverter will change the direction of water flow for my pool.

One of the TH16s will measure my pool temp.
The other TH16 will measure my solar temp (the temperature of the water in the solar tubes).

What I am looking to do is the following:

If Solar Temp > Pool Temp then turn on smart switch
If Solar Temp <= Pool Temp then turn off smart switch

Is this possible to do with Sonoff/TH16/ewelink and Apilio… and other apps like IFTTT or something else if needed?

Hi @mvsette,

The good news is that this should be relatively straightforward.

I’m currently in the process of automating my spa/pool combo to let me heat the spa separately, so have looked into solving a very similar set of issues with reading temperatures and switching 3-way valves.

I don’t know about the Sonoff TH16, I am reading temperature via a Ubibot device, but with luck they will work similarly. The trick is to get readings into IFTTT, and send these to Apilio for storage–unfortunately while you can often see values in Apilio you cannot (at present) do much with them, but IFTTT does let you do that.

So, if you can get the temperature readings into IFTTT, then you can use IFTTT to write these values into two separate Apilio variables (solar_temp and pool_temp). You will probably need to poll IFTTT every so often to retrieve the temperatures (every few minutes should be enough), which I do by setting an Apilio time condition to trigger when required (use the CRON setting – for example, “*/4 * * * *” means trigger every 4 min, which is what I use). Then set up a logicblock in Apilio that is triggered by your time condition, and which tells IFTTT to take the temperatures and send them back to Apilio.

At this point you will have two variables in Apilio that are constantly being refreshed with the temperature readings. You can compare these using a numeric condition, so if solar_temp > pool_temp then turn on smart switch, else turn off smart switch.

Good luck!

@mvsette

Hmmm… it actually might not be. Just looked at the Sonoff / Ewelink IFTTT actions/queries and it does not look easy to get the actual temperature reading, just the event details of when the temperature goes above or below a set threshold. I hope I have missed something, but if that is the case then it would be hard to compare temperature values using the Sonoff.

If the Sonoff device doesn’t do what you need, I know that you can extract the actual temperatures from a Ubibot device, with the WS1 Pro allowing two separate temperature sensors to be connected. (You would need a couple of temperature probes and a USB splitter to connect these–all sold on Amazon, of course!). It isn’t completely straightforward to get the temperature values from the Ubibot (you need a small JavaScript filter within IFTTT to process the data), but if you went down this route I could send that to you.

1 Like

It looks like I will have to go the Ubibot route… so I see all the items I need to buy… so now I need to do some work with apilio and ifttt… what are the monthly costs for them?

Thanks for your help by the way, really appreciate it!

Michael

1 Like

Hi Robin,

Thanks for the advice! I am looking at purchasing either the WS1 Pro or the smart plug version SP1 which allows for 2 temperature probes, but doesn’t have a display. I don’t really need the display. It also has audio jacks instead of micro usb which may be better in my application because I need to run one of the temp probes over 100 feet, and I believe the micro usb signal would fail, whereas the audio 3.5mm cable will not.

Anyhow, what is the JavaScript I would need? Also, do I have to pay monthly fees to IFTTT and/or Apilio (which package)?

Thanks!

Michael

1 Like

Have you thought about running a LoRaWAN probe as the distance is >100ft? I am trying LoRa sensors at the moment but it’s quite difficult to get the data into Apilio…

Hi @mvsette ,

For Apilio the pricing is here:
Apilio - Pricing
You would need the Advanced or Pro plan, depending on how enthusiastic you became (and you can always start with the Advanced and upgrade if necessary). You do need the features of the Advanced plan though. However, as someone who has nothing to do with Apilio, I can honestly say that this is a bargain.

For IFTTT you would almost certainly need the Pro plan
Plans - IFTTT

Do you have WiFi signal there? If so you could always have separate UbiBot WS1 devices at each point where you need to monitor the temperature (you might need a waterproof case). And the WS1 runs off battery if you don’t have power there…

Robin, I can do that possibly… trying to keep my cost down… I’ll see… I may wind up using the SP1 (smart plug) from Ubibot as mentioned… can you tell me more about this Java Script code?

Dan, not sure about LoRa sensors… looked into it, but it looks to be complicated for me.

Thanks!

It is not very complicated. You just have to process the “History of Sensor Data Received”. Field8 is the external temperature from the sensor (I have a WS1 with just one external probe). The data received for some reason does tend to have some blank fields, so I use the filter code to extract the latest non-blank value and set this via Apilio.numericVariableSetValueUpdates.setVariableValue()

Good luck!
Robin

2 Likes

Let me ask you… if I go this route with JavaScript code…

I am basically using the code to find out what Temp1 (Pool) is…
Then, can’t I do the same thing to figure out what Temp2 (Solar) is…
Then, can’t I use JavaScript code to figure out which one is higher (Pool or Solar)?
And finally, can’t I use the result (0 or 1; yes or no; on or off) to utilize IFTTT to turn on a smart switch (If RESULT=0 then turn Smart Switch off… if RESULT=1 then turn Smart Switch on).

Would this work?

1 Like

I think the easiest thing to do is query the temperature for your first sensor and write the value back to an Apilio variable, and query the temperature for your second sensor and write that to a second variable. If you have a sensor that reads two probes you could do it in one call, otherwise you would (probably) need 2 IFTTT routines. You do need to do this every so often to update those variables, but given that temperature does not change too quickly it shouldn’t be necessary to do this more than every couple of minutes or so–to do this I’d use an Apilio time condition (IFTTT doesn’t really have anything comparable) and have that call your “update temperature” applets every few minutes. If you do this you will have your two Apilio variables that are continuously being updated and you can then act on that.

To do so, set up a condition in Apilio that triggers when one of these is less than the other, switching your valves as required depending on the temperature difference. I’m not sure how you are triggering this, but if you have a smart ‘light’ switch you can use this to trigger a relay that allows the valve actuator to draw power from its transformer (most actuators seem to be 24V, so you can’t just pass mains voltage to them. However, if you have a relay that controls whether your 24V current flows or not, then you can set it up.

I’m not sure what actuators you have, but the circuit for a Jandy valve being controlled by a time clock is shown below.
image
If instead of having mains from the time clock passing to the relay you have mains voltage from a smart light switch, then you can easily control the pump direct from Apilio by switching it on or off. Depending on whether you have 120V (as in the diagram) or 240V you will need a different specification of relay (and 24V transformer), but the principle is the same.

At least, this is roughly what I am currently implementing for my situation!

1 Like

This is very similar to what I am trying to do… just wondering if there is a way to avoid all these monthly fees, hence what I said in my previous post…

1 Like

A little secret that you might be interested in: We are currently working on IFTTT queries for Apilio variables. That might help with setups like these :slight_smile:

1 Like

Interesting… can you say more? You can read the variable anyway from IFTTT, so what else are you planning? :slight_smile:

1 Like

you already found the news :slight_smile:

2 Likes