So I think I figured it out, using the web_server
key basically pre-installs a bunch of other libraries, and I think includes some header files that I was inadvertently/unknowingly using. Removing that from my YAML gives the same result you got.
For the moment, you can probably just enable the web server and it’ll be fixed. I tried including ArduinoJson-esphomelib
as a library and still got the same error as you, so I have some rework to do there to use the library properly.
1 Like
I added web_server: and it compiled. I just need to upload the code, hook everything up and I’ll give it a test.
1 Like
I got everything together and fired it up. Under no load, I could see 119.4v so the UART communication was working properly. Initially, I was having problems with the pzem not returning power or amps. I had update_interval set to 1s which the v1.0 board apparently cannot handle. I upped it to 15s initially and everything worked! I currently have it set at 2s which seems to be working fine as well.
Here’s a sense screenshot of the device in action. The first smaller peaks were from my soldering iron. The larger peak is a heat gun and the smaller peaks of about 380 watts are a small air pump.
Here’s the code. Should be able to pass actual voltage as well for more accurate calculations.
esphome:
name: esp_sense_01
platform: ESP8266
board: nodemcuv2
includes:
- espsense.h
libraries:
- "ESPAsyncUDP"
wifi:
ssid: "MYSSID"
password: "1234567890"
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Esp Sense 01 Fallback Hotspot"
password: "password"
captive_portal:
# Enable logging
logger:
# Enable Home Assistant API
api:
ota:
uart:
tx_pin: D1
rx_pin: D2
baud_rate: 9600
sensor:
- platform: pzem004t
current:
name: "ESPSense01 Current"
voltage:
name: "ESPSense01 Voltage"
id: esp_sense_01_voltage
power:
name: "ESPSense01 Power"
id: esp_sense_01_power
update_interval: 2s
custom_component:
# Create ESPSense instance, passing the ID of the sensor it should retrieve
# power data from
- lambda: |-
auto sensor_power = new ESPSense(id(esp_sense_01_power), 120);
return {sensor_power};
1 Like
Nice! Awesome to see it running for someone else. I just fixed the Json dependency too, but didn’t get a chance to upload it yet.
FYI I uploaded a new version that uses ArduinoJson correctly. It’s still using v5, even though v6 is out there, because esphome still pulls v5 for the web server and other purposes. No reason to duplicate a library and take up memory when the usage for ESPSense is so simple anyway.
1 Like
Cool. The firmware compiled with no issues. I’m on vacation so I won’t be able to update the esp8266 until I get home.
Thank you for putting this all together. I know there are a lot of people here asking for something that does just what this does. Especially with being able to accurately monitor 240v devices such A/C units.
2 Likes
I’m a little surprised there hasn’t been others asking questions here. Dozens of posts asking for sense to support other power monitoring adapters and this does just that. If you have a power adapter that you can read using mqtt, home assistant or other methods, you can read that data from senselink or espsense and pass it to sense as an emulated hs110.
4 Likes
This might be nice to integrate directly into HomeAssistant though it would need some refactoring to remove a lot of unneeded stuff.
It could be part of the sense component - maybe I’ll look into that integration
1 Like
Update! Integration seems pretty solid.
Here’s my HomeAssistant configuration.yaml:
sense:
entities:
fan.window_fan:
name: "Window Fan"
power: 62.0
light.dining_room:
name: "Dining Room Lights"
power: 40.0
light.wled:
name: "Fence Lights"
power_template: "{{ states('sensor.wled_estimated_current') | float * 5 / 1000 }}"
and here’s what it looks like in the sense app when I turn all those things on:
The light and the fan stay constant while the LED strip value goes up and down based on the brightness
I’ll probably submit a PR this weekend
5 Likes
Nice! That’s awesome, looking forward to seeing the PR.
This is awesome. Thanks so much for creating this.
I just installed Sense and was looking for a good way to get it to recognize Caseta-controlled loads.
We had a whole house rehab after a small fire last year and I had the opportunity to do what I had always wanted from a wired home-automation standpoint and we went ahead and installed Caseta throughout the whole house.
As for lights, I have 21 distinct lighting circuits in the house, and I was able to quickly set up Home Assistant (I’ve been all HomeKit for automation so far) and then stand up SenseLink. I set up our main kitchen lights and our family room lights and they work great in Sense.
I’m looking forward to being able to combine sets of lights together because of the 20-ish Smart plug limit. I can easily combine those 21 lighting circuits into 10 or 11 by grouping within the same room.
I can’t wait to tinker with this.
Thanks again!
2 Likes
Glad you find it useful!
I’ll admit I’ve been working more on ESPSense this week, and then had been figuring out the MQTT integration. But I had a general idea of how to do the grouped plugs so I’ll get to it soon.
If you have any thoughts or issues on the HASS integration definitely let me know!
I’m excited about ESPSense as well… I have an order of TOPGREENER smart plugs on its was from Amazon to instrument various things around the house, but I’m definitely in need of the grouped plugs as I have so many Casta lights to take care of.
I’m going to look at your code (though I’m not versed in Python, I am a software developer) to see if I can cobble something together. If I get something working and you haven’t arrived there yet, I’ll be sure to submit the code back.
1 Like
@tedhowe @mattlebaugh @james_reilley @kevin1
Update: SenseLink can now pull data from MQTT, and supports Aggregate plugs! The Aggregate plugs are simply specified by the IDs of any other plug types (maybe even other Aggregate? I should test that…) and update dynamically as the “element” plugs change themselves.
I need to build the Docker images for the new version, but the base code is updated in the Github repo. Let me know if anyone has more ideas or runs into issues! I’ll admit the MQTT side isn’t robustly tested, because I don’t personally have any devices publishing to MQTT at the moment. I was just manually publishing to topics to simulate what I thought would be realistic.
2 Likes
I’m hitting an error when I try to start with an aggregate plug defined.
Here’s the error message…
Traceback (most recent call last):
File “./SenseLink.py”, line 258, in
main()
File “./SenseLink.py”, line 254, in main
loop.run_until_complete(tasks)
File “/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/asyncio/base_events.py”, line 579, in run_until_complete
return future.result()
File “./SenseLink.py”, line 163, in start
self.create_instances()
File “./SenseLink.py”, line 127, in create_instances
plugs = aggregate[PLUGS_KEY]
TypeError: list indices must be integers or slices, not str
The rest of my yaml works fine if I remove the aggregate section at the end, but if I add it in, I get the above crash.
Whoops, go figure I push something with a bug and then head out for the evening. Thanks for letting me know, I’ll check it out later! Could you post your aggregate YAML section as well?
It could very well be my yaml… I’m not the best at editing, but here’s the aggregate section:
- aggregate:
- Kitchen_Lights:
mac: 53:75:31:f6:4b:01
alias: “Kitchen Lights”
elements:
- Kitchen_Main_Lights
- Kitchen_Task_Lights
I figured it out. The example in your readme of the aggregate section didn’t have the plug element. I changed by aggregate section to this:
- aggregate:
plugs:
- Kitchen_Lights:
mac: 53:75:31:f6:4b:01
alias: “Kitchen Lights”
elements:
- Kitchen_Main_Lights
- Kitchen_Task_Lights
And now it appears to be working fine.
Thanks so much for this. I combined the four circuits from our kitchen/dining are and it behaves exactly as I would expect as each is turned on/off or dimmed.
1 Like
Good catch, glad you got it working! I’ll fix the example now.
Holy Cow, with mqtt this makes using shelly EMs with sense directly possible. So not only can i link my lights but I can link my Water Heater, EVs, etc. Thanks so much for this!
3 Likes