Help with alexa home node to automate diy spa bath heater with sonoff th16 temperature controlled relay

I have the knowledge to develop this flow on all issues apart from getting node red to get the temp from ewelink to compare the temp against the temp of the set temp value stored in alexa, I have already got alexa to speak the temp of the water no problem, I have alexa setting the aim temp no problem, I just cant get a flow working that compares the current temp against the set target temp, I can control the frequency and anything else involved after, like when to heat and when not to heat,
I have read what i can on global context, objects and arrays but it still has not clicked in my head on how to compare the get and set temp so i can heat or not accordingly,
Thanks in advance and yes my full stop key has stopped working so I apologise for the commas i have replaced them with,

I take it these are standard sonoff devices, not flashed.

If so you can use node-red-contrib-ewelink to poll temp and the device listener may report temp.

yeah i got that far no problem, I just need help with the flow for compoaring the set tgemp against the actual temp so i can turn the heater on in the flow when temp is below target and turn off when above target temp, The flow gets this info from the alexa home node from a thermostat sensor i have created on the home skill device setup

Currently I have Alexa announce the temp every 60 seconds, from the bathroom echo only, I plan to have alexa only announcing when a significant temp change has been sensed, This is within my capabilities , What i cant do is compare the polling temp info every 60 seconds with the settemperaturetargetrequest that alexa sends as a msg payload command with the 60 seconds poll to then switch the relay to required state I am sure its a small flow with a few change and combine nodes but i cant grasp the logic around this issue

Have a look at node-red-contrib-ramp-thermostat.

If that does not help, then provide an example of your flow and inputs, then we can give more advise.


here is a simple comparison, it has a deadband so once it reaches set point it has to fall below dead band value to turn off, this is to stop any oscillation.

[{"id":"20c65ac1.91d14e","type":"inject","z":"57675e72.26a0d8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"20.9","payloadType":"num","x":130,"y":480,"wires":[["f9f5ce00.7a0ed8"]]},{"id":"f9f5ce00.7a0ed8","type":"change","z":"57675e72.26a0d8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload >= $flowContext(\"setpoint\")  ? \t1 \t: payload < $flowContext(\"setpoint\") - $flowContext(\"deadband\") ? \t0 ","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":480,"wires":[["cdd63e01.c0bf2"]]},{"id":"f4ce440d.f28448","type":"inject","z":"57675e72.26a0d8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"20.7","payloadType":"num","x":120,"y":440,"wires":[["f9f5ce00.7a0ed8"]]},{"id":"9d934a44.69583","type":"inject","z":"57675e72.26a0d8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"21","payloadType":"num","x":110,"y":520,"wires":[["f9f5ce00.7a0ed8"]]},{"id":"5c062863.e01be8","type":"inject","z":"57675e72.26a0d8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"21.5","payloadType":"num","x":127.33332824707031,"y":558.6666870117188,"wires":[["f9f5ce00.7a0ed8"]]},{"id":"cdd63e01.c0bf2","type":"switch","z":"57675e72.26a0d8","name":"","property":"payload","propertyType":"msg","rules":[{"t":"istype","v":"number","vt":"number"}],"checkall":"true","repair":false,"outputs":1,"x":410,"y":540,"wires":[["7fa11ff4.ea97b8"]]},{"id":"7fa11ff4.ea97b8","type":"rbe","z":"57675e72.26a0d8","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":550,"y":540,"wires":[["3f5a851.f4bdffa"]]},{"id":"3f5a851.f4bdffa","type":"debug","z":"57675e72.26a0d8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":600,"y":480,"wires":[]},{"id":"2ca75c14.eefb4c","type":"inject","z":"57675e72.26a0d8","name":"set set point","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"21","payloadType":"num","x":160,"y":360,"wires":[["da712b9f.7a0588"]]},{"id":"da712b9f.7a0588","type":"change","z":"57675e72.26a0d8","name":"","rules":[{"t":"set","p":"setpoint","pt":"flow","to":"21","tot":"num"},{"t":"set","p":"deadband","pt":"flow","to":"0.2","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":330,"y":360,"wires":[[]]}]

Already tried ramp thermo, Its not really any use, Its a Alexa integration and a lack of knowledge of java and jsonata that is my downfall, The flow I have so far uses alexa home skill to set up a virtual device "bath water", My th16 is powered from another sonoff called bath pump, reason for this is if the bath heater is to power on while the bath pump is not circulating the spa experience then the heater {which is a modified electric shower} would over heat, When i tell alexa to turn on bath water alexa announces the temp from th16 every 30 seconds and turns on the bath circulation pump, Alexa speaks the variable temp from the bathroom echo only, This all needs tidying up but its not really any use until i can set the aim temp by alexa and leave the flow to automate turning on the heater depending on what aim temp is set and what temp the th16 is returning for the water
[{"id":"dee23e45.11ce5","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"a928712a.5e54e","type":"ewelink-temperature","z":"dee23e45.11ce5","name":"","deviceId":"10007c2879","auth":"eb3b6077.50435","x":940,"y":260,"wires":[["e02d7e6e.1649b"]]},{"id":"522b459f.88006c","type":"debug","z":"dee23e45.11ce5","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":350,"y":40,"wires":[]},{"id":"a45b36d7.03eca","type":"function","z":"dee23e45.11ce5","name":"","func":"msg.payload = { \"type\": \"speakAtVolume\", \n \"payload\": { \"type\": \"regular\", \n \"text\": \"temperature is \" + msg.payload + \" degrees c\",\n \"volume\": 40, \n \"devices\": \"Bathroom input\" }\n }\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":330,"y":380,"wires":[["741d4d74.a13b54","3e7cad97.cdbbc2"]]},{"id":"741d4d74.a13b54","type":"alexa-remote-routine","z":"dee23e45.11ce5","name":"","account":"149ea61b.2e576a","routineNode":{"type":"custom","payload":{"type":"msg","value":"payload"}},"x":640,"y":380,"wires":[[]]},{"id":"e02d7e6e.1649b","type":"change","z":"dee23e45.11ce5","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.temperature","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":320,"wires":[["a45b36d7.03eca"]]},{"id":"5652d37b.7c833c","type":"alexa-home","z":"dee23e45.11ce5","conf":"2cd25a0f.b3e5b6","device":"115907","acknoledge":true,"name":"Bath water","topic":"","x":110,"y":160,"wires":[["a0f6ba62.2973c8"]]},{"id":"a0f6ba62.2973c8","type":"switch","z":"dee23e45.11ce5","name":"","property":"payload","propertyType":"msg","rules":[{"t":"true"},{"t":"false"}],"checkall":"false","repair":false,"outputs":2,"x":310,"y":160,"wires":[["522b459f.88006c","a1375a6e.4de788","f46d4d8f.46a56"],["93c9d635.9fe8c8","ddbe3188.122bd","e0375cb1.4298a"]]},{"id":"a1375a6e.4de788","type":"msg-resend","z":"dee23e45.11ce5","interval":"26","intervalUnit":"secs","maximum":"100","bytopic":false,"clone":false,"firstDelayed":false,"addCounters":false,"waitForResend":false,"highRate":true,"outputCountField":"","outputMaxField":"","name":"","x":630,"y":240,"wires":[["a928712a.5e54e"]]},{"id":"93c9d635.9fe8c8","type":"debug","z":"dee23e45.11ce5","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":350,"y":80,"wires":[]},{"id":"ddbe3188.122bd","type":"change","z":"dee23e45.11ce5","name":"","rules":[{"t":"set","p":"resend_ignore","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":820,"y":160,"wires":[["a1375a6e.4de788"]]},{"id":"f46d4d8f.46a56","type":"alexa-remote-routine","z":"dee23e45.11ce5","name":"","account":"149ea61b.2e576a","routineNode":{"type":"smarthome","payload":{"entity":"25927bde-8baa-441c-aa0e-f4d5eac5199e","action":"turnOn"}},"x":870,"y":60,"wires":[[]]},{"id":"e0375cb1.4298a","type":"alexa-remote-routine","z":"dee23e45.11ce5","name":"","account":"149ea61b.2e576a","routineNode":{"type":"smarthome","payload":{"entity":"25927bde-8baa-441c-aa0e-f4d5eac5199e","action":"turnOff"}},"x":880,"y":120,"wires":[[]]},{"id":"3e7cad97.cdbbc2","type":"debug","z":"dee23e45.11ce5","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":470,"y":440,"wires":[]},{"id":"eb3b6077.50435","type":"ewelink-credentials"},{"id":"149ea61b.2e576a","type":"alexa-remote-account","name":"","authMethod":"proxy","proxyOwnIp":"localhost","proxyPort":"3456","cookieFile":"","refreshInterval":"7","alexaServiceHost":"","amazonPage":"","acceptLanguage":"en-UK","userAgent":"","useWsMqtt":"on","autoInit":"on"},{"id":"2cd25a0f.b3e5b6","type":"alexa-home-conf","username":"Robmak"}]

Ok with node-red-contrib-amazon-echo or node-red-contrib-virtual-smarthome, you could simply say "alexa set water temp to 25" screen shot below device is set as a dimmer. In screenshot you can see the percentage. i said "set water temp to 30" as well.

Also in node-red-contrib-alexa-remote2, you can use the event listener set to device activity. Then when you say "alexa blah blah", you can see the spoken word in msg.payload.description.summary. You would then have to parse out the temp.

Thanks for your help. I looked at your solution and although I have not used it the flow has given me some other ideas on automating my smart home setup with alexa.
My problem was actually just understanding context and how to set it properly using the change node. Once I grasped the concept i have made a fantastic flow does everything and more than i thought possible.
I can post it if anyone interested.
The flow now enables me to set a target temp and the thermostat is checked every 5 seconds. When the temp changes alexa speaks the new temp and informs me whether the heater is on or off. There is a safety bit in there to make sure that the heater can only be powered up if the pump is circulating water. I also wired up some self checking nodes that look for any errors and re run the cookie and re log in to alexa browser if any links breakdown. Obviously making sure everything is safe while doing so just as an extra to stop anyone unexpectedly getting hot water from the heater when not expected.
The target temp can be set and changed at any time during or before bathing.
Cant think of anyway of improving the flow.

Thanks again.
I am learning all the time with node red and it still manages to amaze me on what brilliant software it is. It has saved me so much money from not having to buy the official alexa devices. In conjunction with a broadlink pro a sonnoff rf433 bridge and some old remotes and smart plugs there is literally nothing that node red cannot do.

cheers Rob

Just thought I would inform you I have solved the problem. Made a great flow that does exactly what i wanted and more. Node red is amazing. I have made from an old shower and a 60 amp contactor, sonoff th16 with temp sensor and a large whirlpool bath a voice controlled water spa and heating system that can set the water to any temp and keep the temp for as long as you want. The temp sensor is coated with foil and insulated and taped to the input pipe of bath circulation pump out of sight under the bath. Did it this way so no issues can arise like leaking and if the temp sensor ever needs replacing this would be a simple a quick job to complete. The old shower unit is under the bath and protected by an extra 16 amp rc trip and a 60 amp no (normally open) contactor that is outside the bathroom via 10mm2 twin and earth cable. The sonoff th16 is also outside bathroom and also a sonoff 4 channel device that is controlling the steam room, bathroom lights, hot water / power shower pump and bath whirlpool pump.

I use some simple 433 mhz smart sockets with a broadlink rm pro and sonoff 433 bridge (tasmoto) that interupt the boiler programmer to enable voice controlled heating and hotwater for less than 50 pounds. With node red and some flows I have a smart voice controlled heating and hot water system that makes Hive and the other over priced smart heating packages look basic and unnecessarily complicated to use,

If anyone is interested I will share the flow I have created and help personalise the flow to suit your requirements. The money that can be saved is amazing. How much would a voice controlled bath heater / spa system cost to purchase then install is ridiculous. Making your own control system is much more fun and fulfilling. Basically i tell alexa what temp i want my bath water and it stays bang on that temp. How cool is that. Without pressing a single button or leaving the bath. Could not be any safer as everything has been done to be within and better than current regulations. Made all the smart switches meet outside of the bathroom on a din rail. All the metal objects have been correctly earth bonded and connected as the regs specify.

Good luck, and thanks to everyone who helped with advice while I been on with these projects.

1 Like

Curious to know what your safety overrides are, as I would not rely on just a single temp sensor. I would have a overheat sensor that cuts heat if temp goes to high, this would be hard wired so no issues with wifi or lost signals.

The heater has a overheat sensor that is part of the shower circuit. This cuts out power if the heating unit goes dry or if no flow is pumping. The output from the heater is appx 6 to 8 degrees higher than the current bath water temp which although is hot is not ever scalding temp.
The safety concerns that are pertinent are the electrical safety due to the high amps required for resistance based water heating.In the event of loss of wifi etc just turning off the pump at the bath pnuematic button would stop warm water if an emergency ever happened.

1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.