Wifi Relay as a "simple" energy diverter


Im looking at using a wifi relay to control heating in my house.
I am currently running a EmonPi and a 5kw solar grid tied power system.

Is it possible to have the relay turn on when EmonPi =excess power >3000watts or something similar?!
How hard would this be to make work!

Planning on using it for under floor heating or a seperate hot water cylinder…

Any ideas would be great.


Hi Dan,
you can use a esp8266 wifi module with relay like wemos D1 mini loaded with espeasy firmware which should include also mqtt import plugin. The module will be set to receive via mqtt the active power production. In the rule page you have to write a rule to activate the gpio output connected to the relay when the P>3000. This will work 100%, it is already tested by me. I switched to the next level to control the heating power in order to not feed any excess power in the grid.
i hope it helps

I have been doing this with the WiFi relay from the OEM store for about a year now to turn my EVSE on and off when the amount of solar generated exceeds the “break even” level versus using E7 overnight. I used a node-red flow and had a bunch of triggers with differing delays based on amount of solar generation.

I would advise deciding what cycling delays are acceptable as you probably don’t want the relay on/off/on/off over a few seconds continually.

I went with things like “over break even for 5 minutes, on” - “under break even for 10 minutes, off” - with shorter “on” delays when the output got above the 16A I needed for the EVSE.

I have now moved to a different scheme where I vary the advertised power to the car using an RS485 control link on the EVSE and now the relay is just there to turn on the EVSE when I have just enough power generation to be interesting - but still with a 30 minute off delay.

1 Like

Thanks for the reply, Looks like i will order a wifi relay from the OEM store and have a play!
Any screen shots of how you setup your Node-red flow? or general concept! No idea about this stuff yet!


It’s a little messy right now, but I’ll try for a cleaned up copy and post it soon. Feel free to ask question however, I’ll answer as best as I can!

I had time to have a bit of a play. Seems to working like this!

Not the most complex setup… Will keep playing with it and see where it ends up!

You can use a single Switch - one input mutilple outputs - to save some nodes.

The core of my flow looks like this:

I use two triggers in series as a filter to ensure that the incoming level remains high enough (or low enough) for a period but allows peaks and troughs without switching the relay too many times:


Which says “Once the solar reaches threshold, send 1s and but allow it to drop for at least one minute before sending a 0; then wait for it to remain high for at least 5 minutes before turning power on”.

Conversely, the “off” side has an identical first switch component but the second send a 0 (instead of a 1) after 15 minutes of “low” solar.

I’m still hacking at the “Adaptive Amps” function as I don’t like the way it oscillates just over the total solar leading to a little exporting. More on that soon.

Thanks for the help.

I cant seem to get the MQTT to trigger the relay!
Does anyone have any ideas

Running with a Emon pi and a OEM Wifi relay

Can anyone see any obvious mistakes!!

I and sending a “number” of 1 to turn it on and “0” to turn it off. I have also tried sending the string or “0” or “1” but this made no difference!

You have to add a “1” to the end of the MQTT topic - “emon/heating/control/1” - as there is a version of the same system that has 3 relays to drive (but not on the store).

In my case I left the topic default:

Thanks Got it all working!!

I have 2 relays, I would assume for the second relay i would just put “2”?!

many thanks!

Glad to hear it!

And no, “2” would only work if you had a single WiFi relay device with multiple relays on the board controlled by the same controller.

To address a second WiFi relay you will need to change the MQTT topic and may put the unit number in that, e.g. “emon/heating/control2/1” - and publish to that topic too - does that make sense?


Working like a dream! Sending Excess power to underfloor heating. Will use the second relay for a extra element in the hot water! Feels like I’m winning!

Ok… So little problem when trying to make 2nd WIFI relay work.

To me it seems the MTQQ rx in the relay is stubborn!
I am using “emon/hotwater/control/relay/1” to try and trigger the relay. Sending it a 1. I can see it in the debug being set. But the relay status stays at “0”.

Any ideas would be great! Im addicted I want to control everything now!!

Does the relay work from the Relay Control menu page? i.e. click on the Off / On button and hear it change?

Update - I think you need to remove the “relay/” part of the topic from the node-red flow. The relay just consumes the topic followed by a number for the relay.

Thanks for the help, Yes the relay works when using the control page. Just seems the MTQQ topic is a little confused. I have tried a million difference addresses. I cant even get the Status messages now!

Try using MQTT Lens Chrome extension to test relay control via MQTT:


If you set the MQTTRELAY to subscribe to emon/heating/control/# then, I believe, you publish to emon/heating/control/realy/1 from node-red

Update: To clarify, using the default subscribe of heating/control/# and public topic of heating/status/ I get

[email protected](ro):~$ mosquitto_sub -u emonpi -P emonpimqtt2016 -v -t heating/#
heating/control/relay/1 1
heating/status/relay/1 0
heating/status/ds18b20/1 16.31
heating/status/relay/1 1
heating/status/relay/1 1
heating/status/ds18b20/1 16.31

1 Like

You have reminded me that I am in turn doing something wrong in my own node-red flows, so thanks! I am subscribing to the control topic for relay state and not the actual state as published by the relay! Oops.

1 Like