HA + EcoPlug/Wion + MQTT = success?!

Hi All – I’ve been working with these EcoPlug/Wion units from Home Depot for a while now. Wanted to post my results to get more eyes on them and share my ‘methodology’ …and to see if i’m doing anything unintelligent.

http://www.homedepot.com/p/15-Amp-Wi-Fi-Adapter-Single-Outlet-White-CT-065W/206948864

http://www.homedepot.com/p/Woods-WiOn-Indoor-Wi-Fi-In-Wall-Light-Switch-with-Wireless-Switch-and-Programmable-Timer-50052/206758643

They’re both 8266 based with identical internal control boards, and they run a goofy firmware that allows control only from phone app (and calls out to a server in china). I flashed mine to ESPEasy and have been trying to get them to work properly via HA and via the hardware button on the module itself.

relay: gpio15
button: gpio13

Relay is kept in sync by using a small client-side rule. This rule lets me use different esp8266 modules (electrodragon, sonoff, ecoplug, etc) that all have different GPIO bindings for buttons and actual relay controls without having to change the rules or handling of the module in home-assistant at all. Just setup the devices themselves, give them conventional names, and irrespective of the hardware module/platform, i can use the same rule and home-assistant config for all.

Here’s the config for the buttons, gpio’s and names.

Here is the config page for the button

Here is the config page for the relay itself

Here are the ESPEasy rules that i have configured:

on button#buttonstate do
if [relay#relaystate]=1
gpio,15,0
publish /%sysname%/relay/relaystate,0
else
gpio,15,1
publish /%sysname%/relay/relaystate,1
endif
endon

I’m using HA on a raspi3 using the hassbian installer. I have enabled the mosquitto MQTT broker. Here is my switch config:

  • platform: mqtt
    name: “Breezeway Light”
    state_topic: “/bzwy/relay/relaystate”
    command_topic: “/bzwy/gpio/15”
    payload_on: “1”
    payload_off: “0”
    qos: 1
    retain: true

Essentially, to make the button work properly, I’m using a local rule on the ESP to check the state of the relay and issue a GPIO command based on the current state of the relay. The state of the button is basically ignored. For a while I was updating it and tracking it but then i realized that it seems to have no purpose in this setup.

thanks for your time.

2 Likes

I don’t think I would expose the relay to mqtt to avoid this problem. To switch a light on via mqtt, the mqtt topic would go to the switch, which would then turn the relay on.

A human hitting the switch locally would turn the switch on locally (to avoid dependence on the broker) and then publish to the mqtt broker to update the HA status.

Also, its not clear from your espEasy configuration if the retain flag is set when the status is published, which is also useful to keep status in sync.

Edit: Re-reading the config makes me think that the relay isn’t using mqtt directly, so I’m not sure how things are getting out of sync, but I would still use this approach.

Thanks for the feedback – that makes very good sense to me.

Presently, I have HA controlling the relay via the published GPIO values. This should change.
Rather, I should have HA control the state of the button via MQTT, and have the local button routine control the relay state.

thanks again.

Did you ever get this working? I have the same plug and am working on it as well :slight_smile:

Yes the above config works great. I have a dozen or so of the ecoplug outlet boxes and a couple of the actual switch boxes. Weeks/months of uptime, never had crashes or problems. Controlled everything through home-assistant and even got my wife onboard with using home-assistant to turn the christmas decorations on and off.

In ESPEasy, make sure to set a different CLIENTID for each one or they get grouchy.
I also defined a UDP port in the advanced settings so they could all peer to each other, so when i login to one it shows all active nodes on the network.

I can post screenshots later if that would help

I’d love some updated screenshots! For some reason my switch keeps turning on and I haven’t figured out why!

here are screenshots of my working config.

Do note that each device needs a unique ‘unit nr’ on the main config page…


this next screenshot shows where the ‘unit nr’ is entered, and it must be unique

Thank you! Any chance you could paste your Rules? I’d paste mine but I don’t want to potentially confuse anyone in case it’s different! Thanks again :slight_smile:

the rules are in the first post, updated them there as i was working on the solution

Thanks again. I think partially my error is with the connection to the MQTT server. Every so often I’ll push the button and it won’t respond, or it’ll respond but switch back on its own shortly afterwards. Going to have to do some troubleshooting.

Do these plugs do Current Measurements?

Oh I found my own answer Oops! I have the Wion 50055 it says it does Current Measurements (Energy Use) does anyone know how to get those to MQTT?

On a similar note I made a web page for installing those with Homie firmware software.

I did absolutely NONE of the research or coding just compiled all the steps for doing it. Communicated extensively with the guy who did at The Great Geekery and the guys at Homie Firmware.

Just me documenting the steps. Using the outlets with MQTT and Home Assistant.

http://www.hagensieker.com/blog/page/?post_id=44&title=esp8266-hack-of-inexpensive-wifi-outlet