1
0
mirror of https://github.com/esphome/esphome.git synced 2024-10-06 02:40:56 +01:00

Add total daily energy sensor (#220)

* Add total daily energy sensor

* Add test
This commit is contained in:
Otto Winter 2018-11-09 20:27:19 +01:00 committed by GitHub
parent 0ad61f4a95
commit 8203b8fcd3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 0 deletions

View File

@ -0,0 +1,37 @@
import voluptuous as vol
from esphomeyaml.components import sensor
from esphomeyaml.components.time import sntp
import esphomeyaml.config_validation as cv
from esphomeyaml.const import CONF_MAKE_ID, CONF_NAME, CONF_TIME_ID
from esphomeyaml.helpers import App, Application, get_variable, variable
DEPENDENCIES = ['time']
CONF_POWER_ID = 'power_id'
MakeTotalDailyEnergySensor = Application.MakeTotalDailyEnergySensor
TotalDailyEnergy = sensor.sensor_ns.TotalDailyEnergy
PLATFORM_SCHEMA = cv.nameable(sensor.SENSOR_PLATFORM_SCHEMA.extend({
cv.GenerateID(): cv.declare_variable_id(TotalDailyEnergy),
cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(MakeTotalDailyEnergySensor),
cv.GenerateID(CONF_TIME_ID): cv.use_variable_id(sntp.SNTPComponent),
vol.Required(CONF_POWER_ID): cv.use_variable_id(None),
}))
def to_code(config):
for time in get_variable(config[CONF_TIME_ID]):
yield
for sens in get_variable(config[CONF_POWER_ID]):
yield
rhs = App.make_total_daily_energy_sensor(config[CONF_NAME], time, sens)
make = variable(config[CONF_MAKE_ID], rhs)
sensor.setup_sensor(make.Ptotal_energy, make.Pmqtt, config)
BUILD_FLAGS = '-DUSE_TOTAL_DAILY_ENERGY_SENSOR'
def to_hass_config(data, config):
return sensor.core_to_hass_config(data, config)

View File

@ -360,6 +360,7 @@ CONF_STEP_PIN = 'step_pin'
CONF_DIR_PIN = 'dir_pin'
CONF_SLEEP_PIN = 'sleep_pin'
CONF_SEND_FIRST_AT = 'send_first_at'
CONF_TIME_ID = 'time_id'
CONF_RESTORE_STATE = 'restore_state'
CONF_TIMING = 'timing'
CONF_INVALID_COOLDOWN = 'invalid_cooldown'

View File

@ -310,10 +310,14 @@ sensor:
name: "HLW8012 Voltage"
power:
name: "HLW8012 Power"
id: hlw8012_power
update_interval: 15s
current_resistor: 0.001 ohm
voltage_divider: 2351
change_mode_every: 16
- platform: total_daily_energy
power_id: hlw8012_power
name: "HLW8012 Total Daily Energy"
- platform: hmc5883l
address: 0x68
field_strength_x: