Add total energy
This commit is contained in:
parent
c0a2a3dd07
commit
86a7145a42
|
@ -127,6 +127,16 @@ Breaking Changes
|
|||
(`#231 <https://github.com/OttoWinter/esphomelib/pull/231>`__, `#62 <https://github.com/OttoWinter/esphomedocs/pull/62>`__,
|
||||
`#197 <https://github.com/OttoWinter/esphomeyaml/pull/197>`__)
|
||||
|
||||
- In 1.8.2, you might have noticed that the WiFi performance has been greatly improved. This was due to the new default of
|
||||
the :ref:`power save mode <wifi-power_save_mode>` option: ``NONE``. However, that default made some other ESPs not
|
||||
connect to WiFi at all 😥. So now the default is back to ``LIGHT``. If you had a good WiFi perfomance in 1.8.2, do:
|
||||
|
||||
.. code:: yaml
|
||||
|
||||
wifi:
|
||||
# ...
|
||||
power_save_mode: NONE
|
||||
|
||||
All changes
|
||||
-----------
|
||||
|
||||
|
|
|
@ -300,7 +300,7 @@ use any string you pass it, like ``"ON"`` or ``"OFF"``.
|
|||
.. note::
|
||||
|
||||
For displaying external data on the display, for example data from your Home Assistant instance,
|
||||
you can use the :doc:`/esphomeyaml/components/text_sensor/mqtt` (see the example there for more information).
|
||||
you can use the :doc:`/esphomeyaml/components/text_sensor/mqtt_subscribe` (see the example there for more information).
|
||||
|
||||
.. _display-strftime:
|
||||
|
||||
|
|
|
@ -95,7 +95,7 @@ You can do so with the ``manual_ip:`` option in the WiFi configuration.
|
|||
After putting a manual IP in your configuration, the ESP will no longer need to negotiate
|
||||
a dynamic IP address with the router, thus improving the time until connection.
|
||||
|
||||
Additionally, this can help with :ref:`Over-The-Air updates <ota>` if for example the
|
||||
Additionally, this can help with :doc:`Over-The-Air updates <ota>` if for example the
|
||||
home network doesn't allow for ``.local`` addresses. When a manual IP is in your configuration,
|
||||
the OTA process will automatically choose that as the target for the upload.
|
||||
|
||||
|
|
|
@ -4,3 +4,5 @@ Relay, cookbook/relay, relay.jpg
|
|||
BRUH Multisensor, cookbook/bruh, bruh.png
|
||||
TEMT6000, cookbook/temt6000, temt6000.jpg
|
||||
Non-Invasive Power Meter, cookbook/power_meter, power_meter.jpg
|
||||
Dual Relay Motor Cover, cookbook/dual-r2-cover, sonoff_dual_r2.jpg
|
||||
Total Energy Per Day, cookbook/total_energy, sigma.svg
|
||||
|
|
|
|
@ -1,28 +1,35 @@
|
|||
Dual relay cover motor control
|
||||
==============================
|
||||
|
||||
The following is a possible configuration file for common covers that use a motor with 2 inputs. Only one should be powered at a time (interlocking) to either move the cover up or down. For this the `Sonoff Dual R2 <https://www.itead.cc/sonoff-dual.html>`__ can be used which has two independent relays. Additionally this configuration allows the single button on the Sonoff to control the motion by cycling between: open->stop->down->stop->...
|
||||
The following is a possible configuration file for common covers that use a motor with 2 inputs.
|
||||
Only one should be powered at a time (interlocking) to either move the cover up or down. For this
|
||||
the `Sonoff Dual R2 <https://www.itead.cc/sonoff-dual.html>`__ can be used which has two independent
|
||||
relays. Additionally this configuration allows the single button on the Sonoff to control the motion
|
||||
by cycling between: open->stop->down->stop->...
|
||||
|
||||
These kind of motors automatically stop when the end of the cover movement is reached. However, to be safe, this automation stops powering the motor after 1 minute of movement. In the rare case of the end-stop switch in the motor failing this will reduce the risk for damage or fire.
|
||||
These kind of motors automatically stop when the end of the cover movement is reached. However,
|
||||
to be safe, this automation stops powering the motor after 1 minute of movement. In the rare case
|
||||
of the end-stop switch in the motor failing this will reduce the risk for damage or fire.
|
||||
|
||||
Of the four main components (button sensor, 2 relays switches and the cover), only the cover will be visible to the end-user. The other three are hidden by means of not including a ``name``. This is to prevent accidentally switching on both relays simultaneously from MQTT/Home-assistant as that might be harmful for some motors.
|
||||
Of the four main components (button sensor, 2 relays switches and the cover), only the cover will be
|
||||
visible to the end-user. The other three are hidden by means of not including a ``name``. This is to
|
||||
prevent accidentally switching on both relays simultaneously from MQTT/Home-assistant as that might be harmful
|
||||
for some motors.
|
||||
|
||||
.. note::
|
||||
|
||||
Controlling the cover to quickly (sending new open/close commands within a minute of previous commands) might cause unexpected behaviour (eg: cover stopping halfway). This is because the delayed relay off feature is implemented using asynchronous automations. So every time a open/close command is sent a delayed relay off command is added and old ones are not removed.
|
||||
|
||||
|
||||
|
||||
Controlling the cover to quickly (sending new open/close commands within a minute of previous commands)
|
||||
might cause unexpected behaviour (eg: cover stopping halfway). This is because the delayed relay off
|
||||
feature is implemented using asynchronous automations. So every time a open/close command is sent a
|
||||
delayed relay off command is added and old ones are not removed.
|
||||
|
||||
.. code:: yaml
|
||||
|
||||
esphomeyaml:
|
||||
name: cover
|
||||
platform: espressif8266
|
||||
platform: ESP8266
|
||||
board: esp01_1m
|
||||
board_flash_mode: dout
|
||||
# required until next release (>1.6.2)
|
||||
library_uri: 'https://github.com/OttoWinter/esphomelib.git'
|
||||
|
||||
wifi:
|
||||
ssid: '***'
|
||||
|
@ -79,29 +86,21 @@ Of the four main components (button sensor, 2 relays switches and the cover), on
|
|||
id: cover
|
||||
open_action:
|
||||
# cancel potential previous movement
|
||||
- switch.turn_off:
|
||||
id: close
|
||||
- switch.turn_off: close
|
||||
# perform movement
|
||||
- switch.turn_on:
|
||||
id: open
|
||||
- switch.turn_on: open
|
||||
# wait until cover is open
|
||||
- delay: 60s
|
||||
# turn of relay to prevent keeping the motor powered
|
||||
- switch.turn_off:
|
||||
id: open
|
||||
- switch.turn_off: open
|
||||
close_action:
|
||||
- switch.turn_off:
|
||||
id: open
|
||||
- switch.turn_on:
|
||||
id: close
|
||||
- switch.turn_off: open
|
||||
- switch.turn_on: close
|
||||
- delay: 60s
|
||||
- switch.turn_off:
|
||||
id: close
|
||||
- switch.turn_off: close
|
||||
stop_action:
|
||||
- switch.turn_off:
|
||||
id: open
|
||||
- switch.turn_off:
|
||||
id: close
|
||||
- switch.turn_off: open
|
||||
- switch.turn_off: close
|
||||
optimistic: true
|
||||
|
||||
See Also
|
||||
|
|
|
@ -0,0 +1,242 @@
|
|||
Total Energy Consumption Per Day
|
||||
================================
|
||||
|
||||
Some components (like the :doc:`Sonoff POW R1 </esphomeyaml/components/sensor/hlw8012>`,
|
||||
:doc:`Sonoff POW R2 </esphomeyaml/components/sensor/cse7766>`, :doc:`self-made power meter <power_meter>`, ...)
|
||||
can provide the power usage in watts - so the amount of energy currently consumed per unit of time.
|
||||
|
||||
However, sometimes it's desired to have a sensor that shows the total energy consumption per day in watt **hours**.
|
||||
|
||||
Fortunately, you can use existing components inside esphomeyaml/lib to create such a sensor. The configuration
|
||||
is split up into three main components:
|
||||
|
||||
- A :doc:`template sensor </esphomeyaml/components/sensor/template>`
|
||||
- The power meter (for example :doc:`power_meter`)
|
||||
- A :doc:`time component </esphomeyaml/components/time>`
|
||||
|
||||
The template sensor here is basically just a stub. It doesn't report any values itself (`return {}`), and
|
||||
all state updates will be supplied from outside using `publish_state`. We're giving it a ``name`` so that
|
||||
it shows up in the frontend, an ``id`` so that we can address it in :ref:`lambdas <config-lambda>`.
|
||||
Additionally, a ``unit_of_measurement`` is set (so that the value shows up with a unit in the front end)
|
||||
and the default ``filters`` are disabled (see :ref:`sensor-default_filter`).
|
||||
|
||||
The power meter (here with a generic platform ``<THE_PLATFORM>``), observes the power values as it would normally.
|
||||
Each time the pulse counter receives a value, a lambda is triggered that houses most of the logic. In this lambda,
|
||||
we have a static variable ``last_update`` which we use to get the relative time in hours since the last call of our
|
||||
lambda. Then we just multiply the value ``x`` from the power meter by the relative time (formula ``Energy = Power * time``).
|
||||
Lastly, that value is published to the template sensor.
|
||||
|
||||
And the ``time`` component is in charge of resetting the total energy every day at midnight (you can of course
|
||||
change the time for your needs).
|
||||
|
||||
.. code:: yaml
|
||||
|
||||
sensor:
|
||||
# This is the sensor displaying total energy consumed.
|
||||
- platform: template
|
||||
lambda: 'return {};'
|
||||
update_interval: never
|
||||
name: "Total Daily Energy Usage"
|
||||
id: total_energy
|
||||
unit_of_measurement: kWh
|
||||
# Disable filters
|
||||
filters:
|
||||
accuracy_decimals: 2
|
||||
|
||||
# This is the power meter which outputs values
|
||||
- platform: <THE_PLATFORM>
|
||||
# ...
|
||||
# Disable default filters
|
||||
filters:
|
||||
on_value:
|
||||
lambda: |-
|
||||
static uint32_t last_update = 0;
|
||||
if (last_update == 0)
|
||||
id(total_energy).publish_state(0);
|
||||
// the time since the last update in hours
|
||||
float delta_time = (millis() - last_update) / 1000.0 / 60.0 / 60.0;
|
||||
last_update = millis();
|
||||
|
||||
// x is the power in kW.
|
||||
// the energy consumed in this interval in kWh (E = P * t)
|
||||
float consumed_energy_kwh = x * delta_time;
|
||||
id(total_energy).publish_state(id(total_energy).state + consumed_energy_kwh);
|
||||
|
||||
time:
|
||||
- platform: sntp
|
||||
id: time
|
||||
on_time:
|
||||
# Reset total energy at midnight
|
||||
seconds: 0
|
||||
minutes: 0
|
||||
hours: 0
|
||||
then:
|
||||
lambda: |-
|
||||
id(total_energy).publish_state(0);
|
||||
|
||||
Configuration for Pulse-Counter based Power Meters
|
||||
--------------------------------------------------
|
||||
|
||||
.. code:: yaml
|
||||
|
||||
sensor:
|
||||
# This is the sensor displaying total energy consumed.
|
||||
- platform: template
|
||||
lambda: 'return {};'
|
||||
update_interval: never
|
||||
name: "Total Daily Energy Usage"
|
||||
id: total_energy
|
||||
unit_of_measurement: kWh
|
||||
# Disable filters
|
||||
filters:
|
||||
accuracy_decimals: 2
|
||||
|
||||
# This is the power meter which outputs values
|
||||
- platform: pulse_counter
|
||||
pin: GPIO12
|
||||
unit_of_measurement: 'kW'
|
||||
name: 'Power Meter'
|
||||
filters:
|
||||
- multiply: 0.06
|
||||
on_value:
|
||||
lambda: |-
|
||||
static uint32_t last_update = 0;
|
||||
if (last_update == 0)
|
||||
id(total_energy).publish_state(0);
|
||||
// the time since the last update in hours
|
||||
float delta_time = (millis() - last_update) / 1000.0 / 60.0 / 60.0;
|
||||
last_update = millis();
|
||||
|
||||
// x is the power in kW.
|
||||
// the energy consumed in this interval in kWh (E = P * t)
|
||||
float consumed_energy_kwh = x * delta_time;
|
||||
id(total_energy).publish_state(id(total_energy).state + consumed_energy_kwh);
|
||||
|
||||
time:
|
||||
- platform: sntp
|
||||
id: time
|
||||
on_time:
|
||||
# Reset total energy at midnight
|
||||
seconds: 0
|
||||
minutes: 0
|
||||
hours: 0
|
||||
then:
|
||||
lambda: |-
|
||||
id(total_energy).publish_state(0);
|
||||
|
||||
Configuration for Sonoff POW R1
|
||||
-------------------------------
|
||||
|
||||
.. code:: yaml
|
||||
|
||||
sensor:
|
||||
# This is the sensor displaying total energy consumed.
|
||||
- platform: template
|
||||
lambda: 'return {};'
|
||||
update_interval: never
|
||||
name: "Total Daily Energy Usage"
|
||||
id: total_energy
|
||||
unit_of_measurement: kWh
|
||||
# Disable filters
|
||||
filters:
|
||||
accuracy_decimals: 2
|
||||
|
||||
# This is the power meter which outputs values
|
||||
- platform: hlw8012
|
||||
sel_pin: 5
|
||||
cf_pin: 14
|
||||
cf1_pin: 13
|
||||
# current, voltage, ...
|
||||
power:
|
||||
name: "HLW8012 Power"
|
||||
on_value:
|
||||
lambda: |-
|
||||
static uint32_t last_update = 0;
|
||||
if (last_update == 0)
|
||||
id(total_energy).publish_state(0);
|
||||
// the time since the last update in hours
|
||||
float delta_time = (millis() - last_update) / 1000.0 / 60.0 / 60.0;
|
||||
last_update = millis();
|
||||
|
||||
// x is the power in W.
|
||||
// the energy consumed in this interval in kWh (E = P * t)
|
||||
float consumed_energy_kwh = x * delta_time / 1000.0;
|
||||
id(total_energy).publish_state(id(total_energy).state + consumed_energy_kwh);
|
||||
|
||||
time:
|
||||
- platform: sntp
|
||||
id: time
|
||||
on_time:
|
||||
# Reset total energy at midnight
|
||||
seconds: 0
|
||||
minutes: 0
|
||||
hours: 0
|
||||
then:
|
||||
lambda: |-
|
||||
id(total_energy).publish_state(0);
|
||||
|
||||
Configuration for Sonoff POW R2
|
||||
-------------------------------
|
||||
|
||||
.. code:: yaml
|
||||
|
||||
logger:
|
||||
baud_rate: 0
|
||||
|
||||
uart:
|
||||
rx_pin: RX
|
||||
baud_rate: 4800
|
||||
|
||||
sensor:
|
||||
# This is the sensor displaying total energy consumed.
|
||||
- platform: template
|
||||
lambda: 'return {};'
|
||||
update_interval: never
|
||||
name: "Total Daily Energy Usage"
|
||||
id: total_energy
|
||||
unit_of_measurement: kWh
|
||||
# Disable filters
|
||||
filters:
|
||||
accuracy_decimals: 2
|
||||
|
||||
# This is the power meter which outputs values
|
||||
- platform: cse7766
|
||||
# current, voltage, ...
|
||||
power:
|
||||
name: "CSE7766 Power"
|
||||
on_value:
|
||||
lambda: |-
|
||||
static uint32_t last_update = 0;
|
||||
if (last_update == 0)
|
||||
id(total_energy).publish_state(0);
|
||||
// the time since the last update in hours
|
||||
float delta_time = (millis() - last_update) / 1000.0 / 60.0 / 60.0;
|
||||
last_update = millis();
|
||||
|
||||
// x is the power in W.
|
||||
// the energy consumed in this interval in kWh (E = P * t)
|
||||
float consumed_energy_kwh = x * delta_time / 1000.0;
|
||||
id(total_energy).publish_state(id(total_energy).state + consumed_energy_kwh);
|
||||
|
||||
time:
|
||||
- platform: sntp
|
||||
id: time
|
||||
on_time:
|
||||
# Reset total energy at midnight
|
||||
seconds: 0
|
||||
minutes: 0
|
||||
hours: 0
|
||||
then:
|
||||
lambda: |-
|
||||
id(total_energy).publish_state(0);
|
||||
|
||||
See Also
|
||||
--------
|
||||
|
||||
- :doc:`power_meter`
|
||||
- :doc:`/esphomeyaml/components/sensor/cse7766`
|
||||
- :doc:`/esphomeyaml/components/sensor/hlw8012`
|
||||
- :doc:`/esphomeyaml/components/sensor/pulse_counter`
|
||||
- `Edit this page on GitHub <https://github.com/OttoWinter/esphomedocs/blob/current/esphomeyaml/cookbook/total_energy.rst>`__
|
||||
|
||||
.. disqus::
|
|
@ -0,0 +1 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="24" height="24" viewBox="0 0 24 24"><path d="M5,4H18V9H17L16,6H10.06L13.65,11.13L9.54,17H16L17,15H18V20H5L10.6,12L5,4Z" /></svg>
|
After Width: | Height: | Size: 368 B |
|
@ -749,9 +749,9 @@ This list contains items that are technically already supported by other compone
|
|||
-------------------------------------------------- -------------------------------------------------- --------------------------------------------------
|
||||
`BRUH Multisensor`_ `TEMT6000`_ `Non-Invasive Power Meter`_
|
||||
-------------------------------------------------- -------------------------------------------------- --------------------------------------------------
|
||||
|Dual relay cover motor control|_
|
||||
|Dual Relay Motor Cover|_ |Total Energy Per Day|_
|
||||
-------------------------------------------------- -------------------------------------------------- --------------------------------------------------
|
||||
`Dual relay cover motor control`_
|
||||
`Dual Relay Motor Cover`_ `Total Energy Per Day`_
|
||||
================================================== ================================================== ==================================================
|
||||
|
||||
.. |Garage Door| image:: /esphomeyaml/images/window-open.svg
|
||||
|
@ -772,9 +772,13 @@ This list contains items that are technically already supported by other compone
|
|||
.. |Non-Invasive Power Meter| image:: /esphomeyaml/images/power_meter.jpg
|
||||
:class: component-image
|
||||
.. _Non-Invasive Power Meter: /esphomeyaml/cookbook/power_meter.html
|
||||
.. |Dual relay cover motor control| image:: /esphomeyaml/images/sonoff_dual_r2.jpg
|
||||
.. |Dual Relay Motor Cover| image:: /esphomeyaml/images/sonoff_dual_r2.jpg
|
||||
:class: component-image
|
||||
.. _Dual relay cover motor control: /esphomeyaml/cookbook/dual-r2-cover.html
|
||||
.. _Dual Relay Motor Cover: /esphomeyaml/cookbook/dual-r2-cover.html
|
||||
.. |Total Energy Per Day| image:: /esphomeyaml/images/sigma.svg
|
||||
:class: component-image
|
||||
.. _Total Energy Per Day: /esphomeyaml/cookbook/total_energy.html
|
||||
|
||||
|
||||
Do you have other awesome automations or 2nd order components? Please feel free to add them to the
|
||||
documentation for others to copy. See :doc:`Contributing <guides/contributing>`.
|
||||
|
|
Loading…
Reference in New Issue