arendst / Tasmota

Alternative firmware for ESP8266 and ESP32 based devices with easy configuration using webUI, OTA updates, automation using timers or rules, expandability and entirely local control over MQTT, HTTP, Serial or KNX. Full documentation at
https://tasmota.github.io/docs
GNU General Public License v3.0
21.96k stars 4.77k forks source link

Please add support for wion plug with power monitoring #82

Closed davidelang closed 6 years ago

davidelang commented 7 years ago

This is an esp8266 based outlet available for $25 that does power monitoring

http://www.homedepot.com/p/Woods-WiOn-Indoor-Wi-Fi-Current-Tap-with-2-USB-Charging-Ports-Wireless-Switch-and-Programmable-Timer-50055/206758644 https://www.amazon.com/WiOn-50055-Indoor-Monitor-Wireless/dp/B00ZYLUBJU/ref=sr_1_4?s=hi&ie=UTF8&qid=1487485998&sr=1-4&keywords=wion

an alternate firmware has already been created for the simple switching:

http://thegreatgeekery.blogspot.com/2016/02/ecoplug-wifi-switch-hacking.html with source available on github under GPLv3 https://github.com/scottjgibson/esp8266Switch

LED = 2 relay = 15 button = 13

in the comments at the greatgeedery blog, there is code to do the power monitoring (clock on GPIO0, data on GPIO12)

If you would like me to purchase samples of this line for you to use, contact me with your address and I'll purchase some on Amazon and have them shipped to you

arendst commented 7 years ago

David, as I live in Europe our plugs are different.

But you can try it yourself by tweaking some values at the bottom of file sonoff_template.h. From Scott Gibsons GitHub code (switch only, no power monitoring, different hardware) I conclude the following parameters should make yours work:

  { "User Test",       // Sonoff Basic User Test
     GPIO_USER,        // GPIO00 Optional sensor (pm clock)
     0,
     GPIO_LED1,        // GPIO02 Green Led (1 = On, 0 = Off)
     0, 0, 0, 0, 0, 0, 0, 0, 0,
     GPIO_USER,        // GPIO12 Optional sensor (pm data)
     GPIO_KEY1,        // GPIO13 Button
     0,
     GPIO_REL1,        // GPIO15 Relay (0 = Off, 1 = On)
     0
  }

Just replace the current settings for User Test with the ones above and give it a go.

davidelang commented 7 years ago

This works for the LED, the switch, and the relay.

how big an issue would it be to add code to look at the power stats?

according to comments, something along the following lines would gather data

byte d[16],count; unsigned long value; int watts;

pinMode(12, INPUT_PULLUP); Wire.begin(12, 0);

while(true) { count=0;

// Request 16 bytes Wire.requestFrom(0, 16);

while(count<16) if (Wire.available()) d[count++]=Wire.read(); else yield();

value=d[0]; value=(value<<8)+d[1]; value=(value<<8)+d[2]; value=(value<<8)+d[3];

watts=(value/(400-(value/1800))); Serial.print("Watts: "); Serial.println(watts); delay(10000); }

result of gpio

21:39:16 MQTT: stat/swp03/RESULT = {"GPIO0":5 (I2C SCL), "GPIO12":6 (I2C SDA)}

result of i2cscan

21:39:54 MQTT: stat/swp03/RESULT = {"I2Cscan":"Unknow error at 0x7f"}"}

here is the result of status 0

21:35:05 MQTT: stat/swp03/STATUS = {"Status":{"Module":17, "FriendlyName":"Sonoff", "Topic":"swp03", "ButtonTopic":"0", "Subtopic":"POWER", "Power":1, "PowerOnState":3, "LedState":1, "SaveData":1, "SaveState":1, "ButtonRetain":0, "PowerRetain":0}}

21:35:05 MQTT: stat/swp03/STATUS1 = {"StatusPRM":{"Baudrate":115200, "GroupTopic":"sonoffs", "OtaUrl":"http://domus1:80/api/arduino/sonoff.ino.bin", "Uptime":0, "Sleep":0, "BootCount":7, "SaveCount":21}}

21:35:05 MQTT: stat/swp03/STATUS2 = {"StatusFWR":{"Program":"3.9.18", "Boot":2, "SDK":"1.5.3(aec24ac9)"}}

21:35:05 MQTT: stat/swp03/STATUS3 = {"StatusLOG":{"Seriallog":2, "Weblog":2, "Syslog":0, "LogHost":"domus1", "SSId1":"DDJP2", "SSId2":"the_towed", "TelePeriod":60}}

21:35:05 MQTT: stat/swp03/STATUS4 = {"StatusMEM":{"ProgramSize":440, "Free":580, "Heap":26, "SpiffsStart":1024, "SpiffsSize":3052, "FlashSize":1024, "ProgramFlashSize":4096, "FlashChipMode",2}}

21:35:05 MQTT: stat/swp03/STATUS5 = {"StatusNET":{"Host":"swp03-3128", "IP":"10.6.1.3", "Gateway":"10.0.0.1", "Subnetmask":"255.0.0.0", "Mac":"38:2B:78:08:AC:38", "Webserver":2, "WifiConfig":3}}

21:35:05 MQTT: stat/swp03/STATUS6 = {"StatusMQT":{"Host":"10.6.0.0", "Port":1883, "ClientMask":"DVES_%06X", "Client":"DVES_08AC38", "User":"DVES_USER", "MAX_PACKET_SIZE":1000, "KEEPALIVE":15}}

21:35:05 MQTT: stat/swp03/STATUS7 = {"StatusTIM":{"UTC":"Sun Feb 19 20:35:05 2017", "Local":"Sun Feb 19 21:35:05 2017", "StartDST":"Sun Mar 26 02:00:00 2017", "EndDST":"Sun Oct 29 03:00:00 2017", "Timezone":1}}

21:35:05 MQTT: stat/swp03/STATUS10 = {"StatusSNS":{"Time":"2017-02-19T21:35:05", "BH1750":{"Illuminance":0}}}

I am getting sensor reports

21:39:49 MQTT: tele/swp03/SENSOR = {"Time":"2017-02-19T21:39:49", "BH1750":{"Illuminance":54612}}

davidelang commented 7 years ago

Thanks for merging the basic support. I have a branch that is fetching the sensor data and outputs it as 4 hex values and 4 decimal values (4 bytes each), I haven't made much progress decoding them (any assistance would be appriciated) I posted a bunch of the raw data at https://bitbucket.org/xoseperez/espurna/issues/48/ecoplug-power-sensing where the question was also raised

davidelang commented 7 years ago

I picked up a varister and did some power monitoring on this device at different voltages, the results are posted at (http://lang.hm/wion) if anyone is able to make any progress decoding the data

the setup is with the wion plugged into the sonoff pow and both logging every few seconds. the values on the wion get reset every time they are read.

It seems that these devices get very unhappy at ~40v AC