I think problem is not in the custom sensor itself. Your configuration file contains entries which seem to be pertaining to Home Assistant rather than ESPHome framework: default_config
, tts
, systemmonitor
senros, sonoff
, workday
platform for binary sensor. None of that exists in the context of an ESPHome device, so I’m guessing that’s simply your HASS config file, is it?
ESPHome is used for generating a custom firmware for ESP32 or ESP8266 devices. While it shares much of Home Assistant’s philosophy and structure of configuration files, it serves a completely different purpose. If you simply add ESPHome custom sensor to your HASS config, it just won’t work. HASS doesn’t have a custom
platform for sensors.
If you’re trying to hook up the ZMPT101B senor to the RPi4 itself, you’ll need some additional components. The sensor doesn’t have any digital communication interfaces, simply outputs voltage in range 0-5V. RPi4 doesn’t have any analog-to-digital converters on board, so you’ll need to add one and use one of native Home Assistant integrations to control it.
There’s a nice article on Adafruit on how to hook up an ADC to RPi.
In case you’re still interested in building your own ESP-based device using ZMPT101B, here’s how to use it with ESPHome: if you strip the parts of configuration file which are not valid for ESPHome, leaving something like this:
#esphome - added by Cameron
esphome:
platform: ESP8266
board: esp07
name: custom
includes:
- zmpt101b_custom_sensor.h
sensor:
- platform: custom
lambda: |-
auto my_sensor = new ZMPT101B();
App.register_component(my_sensor);
return {my_sensor};
sensors:
name: "My custom Sensor"
and add `#include “esphome.h” directive to the .h file, firmware compiles correctly (I just picked a random platform, board, and name; likely this will not match your project).
If you want integration with Home Assistant, you’ll need to set up API component.
# Example configuration entry
api:
password: !secret api_password
There are additional integrations available for grabbing data from Home Assistant:
You’ll also need to configure WiFi component so the device you’re building can actually connect to the network.
ESPHome also comes with support for a range of ADC devices.