Giter Site home page Giter Site logo

iamernie / espsense Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cbpowell/espsense

0.0 1.0 0.0 60 KB

Use ESPHome to emulate TP-Link Kasa HS110 plugs, and report energy usage to your Sense Home Energy Monitor (or anything else on your network!) via ESP8266/ESP32 devices

License: MIT License

C++ 100.00%

espsense's Introduction

ESPSense

Use ESPHome to create virtual TP-Link Kasa HS110 plugs, that report energy usage to your Sense Home Energy Monitor

Similar to the SenseLink project, ESPSense is an ESPHome custom component that emulates the protocol of TP-Link Kasa HS110 energy monitoring plugs. This lets you use your own ESP devices to report energy usage directly to your Sense Home Energy Monitor!

You should use this tool at your own risk! Sense is not obligated to provide any support related to issues with this project, and there's no guarantee everything will reliably work, or even work at all. Neither I or Sense can guarantee it won't affect your Sense data, particularly if things go wrong!

Confirmed Compatible Smart Plugs

One of the more useful cases is flashing other (commercial) energy-monitoring smart plugs with ESPHome, and then using them with ESPSense with no other integration required. Check out the wiki for details on confirmed "conversions" of other plugs, and an OTA flash guide!

The focus on the wiki is for plugs that are re-flashable "over the air" for simplicity, but if you're comfortable with soldering (and opening the plug) there are an incredible number of compatible plugs/devices compatible with ESPHome.

Usage

Place the espsense.h custom component in your ESPHome build directory, and add the custom_component details and lambda to your YAML as per the ESPHome directions - from the included example YAML file:

esphome:
  name: espsense
  ...
  # Include espsense.h custom component file
  includes:
    - espsense.h
  # Uses the libraries:
  # - ESPAsyncUDP, to handle UDP communication
  # - ArduinoJson-esphomelib, which might already be included if using the ESPHome webserver
  libraries:
    - "ESPAsyncUDP"
    - "[email protected]"
    

# Template sensor as an example
sensor:
  - platform: template
    name: Test Sensor
    id: test_sensor
    unit_of_measurement: W
  
custom_component:
  # Create ESPSense instance, passing the ID of the sensor it should retrieve
  # power data from
- lambda: |-
    float voltage = 120.0;
    auto sensor_power = new ESPSense(id(test_sensor), voltage);
    return {sensor_power};

Note that whatever sensor you tell ESPSense to monitor is assumed to report a state in the units of watts! If you want to report the power usage of a device indirectly (such as scaled on another parameter, or simply if on or off), you'll need to create a template sensor in ESPHome to calculate/report the wattage.

By default, the MAC address of your ESP device will be reported to Sense. You can configure that manually if desired. See the espsense.h file for the alternate constructor methods.

Advanced Usage

If you're using a device that measures power/voltage/current of more than one thing, ESPSense also supports reporting back multiple "plugs" to Sense. In the custom component lambda, you can configure each plug and add it to the ESPSense component. The plug voltage_sid and current_sid sensor ID values are optional, and ESPSense will fall back to using the specified static voltage and calculating current from power / voltage, respectively, if not specified.

custom_component:
  # Create ESPSense instance, passing the ID of the sensor it should retrieve
  # power data from
- lambda: |-
    // Define "plugs"
    ESPSensePlug plug1 = ESPSensePlug(id(power_sensor1), "50:c7:bf:f6:2b:01", "plug1", 120.0);
    ESPSensePlug plug2 = ESPSensePlug(id(power_sensor2), "50:c7:bf:f6:2b:02", "plug2", 120.0);
    // Plug1 also measures voltage
    plug1.voltage_sid = voltage_sensor1; // ID of voltage sensor
    // Add to ESPSense
    auto sense = new ESPSense();
    sense->addPlug(plug1);
    sense->addPlug(plug2);
    return {sense};

Sense does not currently care about plug voltage or current readings, but this is implemented to support data collection by things other than Sense, or in case Sense does eventually implement it!

Copyright 2020, Charles Powell

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.