I'm an ESPHome n00b, and I got two Sonoff S31 devices working... Can someone help me to understand some YAML questions I have?

Hi Everyone,

LOL I went down a rabbit hole with ESPhome… All I wanted was some basic power monitoring, and then 3 days later, I found myself taking apart smart plugs, flashing ESPhome, and taking a deep dive into YAML. So… I’ll just paste my YAML below as a starting point.

#Basic ESPhome Configuration
esphome:
  name: server-closet
  friendly_name: Server Closet Power Meter
  platform: ESP8266
  board: esp01_1m

uart:
  rx_pin: RX
  baud_rate: 4800

# Enable logging
logger:
  baud_rate: 0

# Enable Home Assistant API
api:
  encryption:
    key: "blahblah"

ota:
  password: "blahblah"

#WiFi + Web Server Configuration
wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

web_server:
  port: 80
  include_internal: true

#Relay Configuration
switch:
  - platform: gpio
    name: "Relay"
    icon: "mdi:power-socket-us"
    pin: GPIO12
    id: relay
    restore_mode: ALWAYS_ON

#Physical Power Button Configuratoin
binary_sensor:
  - platform: gpio
    pin:
      number: GPIO0
      mode: INPUT_PULLUP
      inverted: True
    name: "Physical Power Button"
    on_press:
      - switch.toggle: relay

sensor:
  - platform: wifi_signal
    name: "WiFi Signal"
    update_interval: 60s
  - platform: cse7766
    current:
      name: "Current"
      accuracy_decimals: 2
    voltage:
      name: "Voltage"
      accuracy_decimals: 1
    power:
      name: "Power"
      accuracy_decimals: 2
      id: my_power

time:
  - platform: sntp
    id: my_time

#Enable the device LED
status_led:
  pin: GPIO13

So… good news! This works! And now in my home assistant dashboard, I can view the power usage. So I’ve at least gotten my basic needs taken care of. I don’t think I expected how “not out of the box” it would be haha.

Questions:

  1. How does Home Assistant know which to expose as entities?
  2. If I change any of the names, then any automation that relies on that entity will break, right? I’ll need to update those to match the name.
  3. I have friendly_name set, but if I try to use $friendly_name in the sensor names down below, I don’t actually see the friendly name. Like… it just has the dollar signs + variable name in there. What am I doing wrong here? I’ve tried to copy / paste working configs.
  4. I understand the home assistant API key. What does the “ota” config under it do?
  5. What is uart?
  6. What does the “time” piece do?
  7. What do I need to do, in terms of multiplication factor, to show kW instead of W? Or would it be best to keep it in W and do the conversion in HA?

Okay… that’s enough for now. Thanks!

Basically everything is available, except those marked as ‘internal’

Correct

This works for me:


#Binary Sensor.
- platform: wifi_signal
    name: ${friendly_name} WiFi Signal
    update_interval: 60s
Status

It allows the device to reflash Over The Air, meaning by using wifi.

Serial port

it tells the device to use an sntp time source

Totally up you :grin:

An ESP device typically have no RTC (Real Time Clock) module, like a computer have.
A RTC module is pretty much just a clock with a little battery that keeps it running when you turn off the power to the device.
When there is no RTC and the power is cut, then the clock gets reset and when you turn the power back on, then it will start from zero again. Zero in this case might be some hardcoded date, like midnight at January 1. 1970.
SNTP is one solution to counter this problem, which is done by asking on the network (or internet) for a time and date and then use that. This might take some time and require some resources, which might be unwanted on a battery-powered device.
The other solution is to connect the ESP to a RTC module, just like the one in a computer. This RTC will have its own battery and provide the clock fast to the ESP, which can then get on with its tasks.
If you need to time in your setup, then consider looking into a RTC module. They are often not that expensive, but check up with the ESPHome documentation about what is compatible.

Personally I prefer to use HA’s clock :stuck_out_tongue:

# Sync time with Home Assistant.
time:
  - platform: homeassistant
    id: homeassistant_time
1 Like

It still takes time for the network to get up and request the time and it drains resources on battery powered devices.

Hey Folks!

A few issues here… I’m hoping someone might have some feedback here.

  1. Every now and then, it seems like my device just turns off and on. Is there anything odd in my YAML that would cause that?

  2. The Blue LED just blinks. That’s not super useful. I’d rather have it on if it’s connected to WiFi, and off it’s not connected to WiFi. Any easy way to do that?

  3. My logging interval is set to 60s, but voltage, etc are being output MANY times per second. Example log file below. What do I need to do to fix that?

  4. Everything else look okay in my YAML?

YAML:

#Basic ESPhome Configuration
esphome:
  name: nas
  friendly_name: NAS Power Meter
  platform: ESP8266
  board: esp01_1m

#uart  
uart:
  rx_pin: RX
  baud_rate: 4800

#Enable logging
logger:
  baud_rate: 0

#Enable Home Assistant API
api:
  encryption:
    key: "blahblahblah"

ota:
  password: "blahblahblahf"

#WiFi + Web Server Configuration
wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
web_server:
  port: 80
  include_internal: true

#Relay Configuration
switch:
  - platform: gpio
    name: "Relay"
    icon: "mdi:power-socket-us"
    pin: GPIO12
    id: relay
    restore_mode: ALWAYS_ON

#Physical Power Button Configuratoin
binary_sensor:
  - platform: gpio
    pin:
      number: GPIO0
      mode: INPUT_PULLUP
      inverted: True
    name: "Physical Power Button"
    on_press:
      - switch.toggle: relay

#Sensor Configuration
sensor:
  - platform: wifi_signal
    name: "WiFi Signal"
    update_interval: 60s
  - platform: cse7766
    current:
      name: "Current"
      accuracy_decimals: 2
    voltage:
      name: "Voltage"
      accuracy_decimals: 1
    power:
      name: "Daily Energy"
      accuracy_decimals: 2
      id: my_power

#Time
time:
  - platform: sntp
    id: my_time

#Enable the device LED
status_led:
  pin:
    number: GPIO13
    inverted: True

LOG EXAMPLE:

[08:44:54][D][sensor:093]: 'Voltage': Sending state 121.03896 V with 1 decimals of accuracy
[08:44:54][D][sensor:093]: 'Daily Energy': Sending state 0.00000 W with 2 decimals of accuracy
[08:44:54][D][sensor:093]: 'Current': Sending state 0.00000 A with 2 decimals of accuracy
[08:44:54][D][sensor:093]: 'Voltage': Sending state 121.03896 V with 1 decimals of accuracy
[08:44:54][D][sensor:093]: 'Daily Energy': Sending state 0.00000 W with 2 decimals of accuracy
[08:44:54][D][sensor:093]: 'Current': Sending state 0.00000 A with 2 decimals of accuracy
[08:44:54][D][sensor:093]: 'Voltage': Sending state 121.03896 V with 1 decimals of accuracy
[08:44:54][D][sensor:093]: 'Daily Energy': Sending state 0.00000 W with 2 decimals of accuracy
[08:44:54][D][sensor:093]: 'Current': Sending state 0.00000 A with 2 decimals of accuracy
[08:44:54][D][sensor:093]: 'Voltage': Sending state 121.03896 V with 1 decimals of accuracy
[08:44:54][D][sensor:093]: 'Daily Energy': Sending state 0.00000 W with 2 decimals of accuracy
[08:44:54][D][sensor:093]: 'Current': Sending state 0.00000 A with 2 decimals of accuracy
[08:44:54][D][sensor:093]: 'Voltage': Sending state 121.03896 V with 1 decimals of accuracy
[08:44:54][D][sensor:093]: 'Daily Energy': Sending state 0.00000 W with 2 decimals of accuracy
[08:44:54][D][sensor:093]: 'Current': Sending state 0.00000 A with 2 decimals of accuracy
[08:44:55][D][sensor:093]: 'Voltage': Sending state 121.03896 V with 1 decimals of accuracy
[08:44:55][D][sensor:093]: 'Daily Energy': Sending state 0.00000 W with 2 decimals of accuracy
[08:44:55][D][sensor:093]: 'Current': Sending state 0.00000 A with 2 decimals of accuracy
[08:44:55][D][sensor:093]: 'Voltage': Sending state 121.03896 V with 1 decimals of accuracy
[08:44:55][D][sensor:093]: 'Daily Energy': Sending state 0.00000 W with 2 decimals of accuracy
[08:44:55][D][sensor:093]: 'Current': Sending state 0.00000 A with 2 decimals of accuracy
[08:44:55][D][sensor:093]: 'Voltage': Sending state 121.03896 V with 1 decimals of accuracy
[08:44:55][D][sensor:093]: 'Daily Energy': Sending state 0.00000 W with 2 decimals of accuracy
[08:44:55][D][sensor:093]: 'Current': Sending state 0.00000 A with 2 decimals of accuracy
[08:44:55][D][sensor:093]: 'Voltage': Sending state 121.03896 V with 1 decimals of accuracy
[08:44:55][D][sensor:093]: 'Daily Energy': Sending state 0.00000 W with 2 decimals of accuracy
[08:44:55][D][sensor:093]: 'Current': Sending state 0.00000 A with 2 decimals of accuracy
[08:44:55][D][sensor:093]: 'Voltage': Sending state 121.03896 V with 1 decimals of accuracy
[08:44:55][D][sensor:093]: 'Daily Energy': Sending state 0.00000 W with 2 decimals of accuracy
[08:44:55][D][sensor:093]: 'Current': Sending state 0.00000 A with 2 decimals of accuracy
[08:44:55][D][sensor:093]: 'Voltage': Sending state 121.03896 V with 1 decimals of accuracy
[08:44:55][D][sensor:093]: 'Daily Energy': Sending state 0.00000 W with 2 decimals of accuracy
[08:44:55][D][sensor:093]: 'Current': Sending state 0.00000 A with 2 decimals of accuracy
[08:44:55][D][sensor:093]: 'Voltage': Sending state 121.03896 V with 1 decimals of accuracy
[08:44:55][D][sensor:093]: 'Daily Energy': Sending state 0.00000 W with 2 decimals of accuracy
[08:44:55][D][sensor:093]: 'Current': Sending state 0.00000 A with 2 decimals of accuracy
[08:44:55][D][sensor:093]: 'Voltage': Sending state 121.03896 V with 1 decimals of accuracy
[08:44:55][D][sensor:093]: 'Daily Energy': Sending state 0.00000 W with 2 decimals of accuracy
[08:44:55][D][sensor:093]: 'Current': Sending state 0.00000 A with 2 decimals of accuracy
[08:44:55][D][sensor:093]: 'Voltage': Sending state 121.03896 V with 1 decimals of accuracy
[08:44:55][D][sensor:093]: 'Daily Energy': Sending state 0.00000 W with 2 decimals of accuracy
[08:44:55][D][sensor:093]: 'Current': Sending state 0.00000 A with 2 decimals of accuracy
[08:44:55][D][sensor:093]: 'Voltage': Sending state 121.03896 V with 1 decimals of accuracy
[08:44:55][D][sensor:093]: 'Daily Energy': Sending state 0.00000 W with 2 decimals of accuracy
[08:44:55][D][sensor:093]: 'Current': Sending state 0.00000 A with 2 decimals of accuracy
[08:44:56][D][sensor:093]: 'Voltage': Sending state 121.03896 V with 1 decimals of accuracy
[08:44:56][D][sensor:093]: 'Daily Energy': Sending state 0.00000 W with 2 decimals of accuracy
[08:44:56][D][sensor:093]: 'Current': Sending state 0.00000 A with 2 decimals of accuracy
[08:44:56][D][sensor:093]: 'Voltage': Sending state 121.03896 V with 1 decimals of accuracy
[08:44:56][D][sensor:093]: 'Daily Energy': Sending state 0.00000 W with 2 decimals of accuracy
[08:44:56][D][sensor:093]: 'Current': Sending state 0.00000 A with 2 decimals of accuracy
[08:44:56][D][sensor:093]: 'Voltage': Sending state 121.03896 V with 1 decimals of accuracy
[08:44:56][D][sensor:093]: 'Daily Energy': Sending state 0.00000 W with 2 decimals of accuracy
[08:44:56][D][sensor:093]: 'Current': Sending state 0.00000 A with 2 decimals of accuracy
[08:44:56][D][sensor:093]: 'Voltage': Sending state 121.03896 V with 1 decimals of accuracy
[08:44:56][D][sensor:093]: 'Daily Energy': Sending state 0.00000 W with 2 decimals of accuracy
[08:44:56][D][sensor:093]: 'Current': Sending state 0.00000 A with 2 decimals of accuracy
[08:44:56][D][sensor:093]: 'Voltage': Sending state 121.03896 V with 1 decimals of accuracy
[08:44:56][D][sensor:093]: 'Daily Energy': Sending state 0.00000 W with 2 decimals of accuracy
[08:44:56][D][sensor:093]: 'Current': Sending state 0.00000 A with 2 decimals of accuracy
[08:44:56][D][sensor:093]: 'Voltage': Sending state 121.03896 V with 1 decimals of accuracy
[08:44:56][D][sensor:093]: 'Daily Energy': Sending state 0.00000 W with 2 decimals of accuracy
[08:44:56][D][sensor:093]: 'Current': Sending state 0.00000 A with 2 decimals of accuracy
[08:44:56][D][sensor:093]: 'Voltage': Sending state 121.03896 V with 1 decimals of accuracy
[08:44:56][D][sensor:093]: 'Daily Energy': Sending state 0.00000 W with 2 decimals of accuracy
[08:44:56][D][sensor:093]: 'Current': Sending state 0.00000 A with 2 decimals of accuracy
[08:44:56][D][sensor:093]: 'Voltage': Sending state 121.03896 V with 1 decimals of accuracy
[08:44:56][D][sensor:093]: 'Daily Energy': Sending state 0.00000 W with 2 decimals of accuracy
[08:44:56][D][sensor:093]: 'Current': Sending state 0.00000 A with 2 decimals of accuracy
[08:44:56][D][sensor:093]: 'Voltage': Sending state 121.03896 V with 1 decimals of accuracy
[08:44:56][D][sensor:093]: 'Daily Energy': Sending state 0.00000 W with 2 decimals of accuracy
[08:44:56][D][sensor:093]: 'Current': Sending state 0.00000 A with 2 decimals of accuracy
[08:44:57][D][sensor:093]: 'Voltage': Sending state 121.03896 V with 1 decimals of accuracy
[08:44:57][D][sensor:093]: 'Daily Energy': Sending state 0.00000 W with 2 decimals of accuracy
[08:44:57][D][sensor:093]: 'Current': Sending state 0.00000 A with 2 decimals of accuracy
[08:44:57][D][sensor:093]: 'Voltage': Sending state 121.03896 V with 1 decimals of accuracy
[08:44:57][D][sensor:093]: 'Daily Energy': Sending state 0.00000 W with 2 decimals of accuracy
[08:44:57][D][sensor:093]: 'Current': Sending state 0.00000 A with 2 decimals of accuracy
[08:44:57][D][sensor:093]: 'Voltage': Sending state 121.03896 V with 1 decimals of accuracy
[08:44:57][D][sensor:093]: 'Daily Energy': Sending state 0.00000 W with 2 decimals of accuracy
[08:44:57][D][sensor:093]: 'Current': Sending state 0.00000 A with 2 decimals of accuracy
[08:44:57][D][sensor:093]: 'Voltage': Sending state 121.03896 V with 1 decimals of accuracy
[08:44:57][D][sensor:093]: 'Daily Energy': Sending state 0.00000 W with 2 decimals of accuracy
[08:44:57][D][sensor:093]: 'Current': Sending state 0.00000 A with 2 decimals of accuracy
[08:44:57][D][sensor:093]: 'Voltage': Sending state 121.03896 V with 1 decimals of accuracy
[08:44:57][D][sensor:093]: 'Daily Energy': Sending state 0.00000 W with 2 decimals of accuracy
[08:44:57][D][sensor:093]: 'Current': Sending state 0.00000 A with 2 decimals of accuracy
[08:44:57][D][sensor:093]: 'Voltage': Sending state 121.03896 V with 1 decimals of accuracy
[08:44:57][D][sensor:093]: 'Daily Energy': Sending state 0.00000 W with 2 decimals of accuracy
[08:44:57][D][sensor:093]: 'Current': Sending state 0.00000 A with 2 decimals of accuracy

Thank you in advance!!