forked from esphome/esphome-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c1fe08f
commit fb22c08
Showing
9 changed files
with
267 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
Custom Climate | ||
============== | ||
|
||
This integration can be used to create custom switches in ESPHome | ||
using the C++ (Arduino) API. | ||
|
||
Please first read :doc:`/components/sensor/custom` guide, | ||
the same principles apply here. | ||
|
||
The example below is an example of a custom climate device - all climate devices must override | ||
two methods (:apiclass:`Climate <climate::Climate>`): | ||
|
||
- ``traits``: This should return a :apiclass:`ClimateTraits <climate::ClimateTraits>` object | ||
representing the capabilities of the climate device. | ||
- ``control``: This receives a :apiclass:`ClimateCall <climate::ClimateCall>` object that contains | ||
the command the user tried to set. | ||
|
||
.. code-block:: cpp | ||
#include "esphome.h" | ||
class MyCustomClimate : public Component, public Climate { | ||
public: | ||
void setup() override { | ||
// This will be called by App.setup() | ||
} | ||
void control(const ClimateCall &call) override { | ||
if (call.get_mode().has_value()) { | ||
// User requested mode change | ||
ClimateMode mode = *call.get_mode(); | ||
// Send mode to hardware | ||
// ... | ||
// Publish updated state | ||
this->mode = mode; | ||
this->publish_state(); | ||
} | ||
if (call.get_target_temperature().has_value()) { | ||
// User requested target temperature change | ||
float temp = *call.get_target_temperature(); | ||
// Send target temp to climate | ||
// ... | ||
} | ||
} | ||
}; | ||
(Store this file in your configuration directory, for example ``my_climate.h``) | ||
|
||
And in YAML: | ||
|
||
.. code-block:: yaml | ||
# Example configuration entry | ||
esphome: | ||
includes: | ||
- my_switch.h | ||
climate: | ||
- platform: custom | ||
lambda: |- | ||
auto my_custom_climate = new MyCustomClimate(); | ||
App.register_component(my_custom_climate); | ||
return {my_custom_climate}; | ||
climates: | ||
- name: "My Custom Climate" | ||
Configuration variables: | ||
|
||
- **lambda** (**Required**, :ref:`lambda <config-lambda>`): The lambda to run for instantiating the | ||
climate(s). | ||
- **switches** (**Required**, list): A list of switches to initialize. The length here | ||
must equal the number of items in the ``return`` statement of the ``lambda``. | ||
|
||
- All options from :ref:`Climate <config-climate>`. | ||
|
||
See :apiclass:`Climate <climate::Climate>` | ||
|
||
See Also | ||
-------- | ||
|
||
- :ghedit:`Edit` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
Custom Cover | ||
============ | ||
|
||
This integration can be used to create custom covers in ESPHome | ||
using the C++ (Arduino) API. | ||
|
||
Please first read :doc:`/components/sensor/custom` guide, | ||
the same principles apply here. | ||
|
||
The example below is an example of a custom cover - all covers must override | ||
two methods: | ||
|
||
- ``get_traits``: This should return a :apiclass:`CoverTraits <cover::CoverTraits>` object | ||
representing the capabilities of the cover. | ||
- ``control``: This receives a :apiclass:`CoverCall <cover::CoverCall>` object that contains | ||
the command the user tried to set. | ||
|
||
.. code-block:: cpp | ||
#include "esphome.h" | ||
class MyCustomCover : public Component, public Cover { | ||
public: | ||
void setup() override { | ||
// This will be called by App.setup() | ||
pinMode(5, INPUT); | ||
} | ||
CoverTraits get_traits() override { | ||
auto traits = CoverTraits(); | ||
traits.set_is_assumed_state(false); | ||
traits.set_supports_position(true); | ||
traits.set_supports_tilt(false); | ||
return traits; | ||
} | ||
void control(const CoverCall &call) override { | ||
// This will be called every time the user requests a state change. | ||
if (call.get_position().has_value()) { | ||
float pos = *call.get_position(); | ||
// Write pos (range 0-1) to cover | ||
// ... | ||
// Publish new state | ||
this->position = pos; | ||
this->publish_state(); | ||
} | ||
if (call.get_stop()) { | ||
// User requested cover stop | ||
} | ||
} | ||
}; | ||
(Store this file in your configuration directory, for example ``my_cover.h``) | ||
|
||
And in YAML: | ||
|
||
.. code-block:: yaml | ||
# Example configuration entry | ||
esphome: | ||
includes: | ||
- my_cover.h | ||
cover: | ||
- platform: custom | ||
lambda: |- | ||
auto my_custom_cover = new MyCustomCover(); | ||
App.register_component(my_custom_cover); | ||
return {my_custom_cover}; | ||
covers: | ||
- name: "My Custom Cover" | ||
Configuration variables: | ||
|
||
- **lambda** (**Required**, :ref:`lambda <config-lambda>`): The lambda to run for instantiating the | ||
cover(s). | ||
- **covers** (**Required**, list): A list of covers to initialize. The length here | ||
must equal the number of items in the ``return`` statement of the ``lambda``. | ||
|
||
- All options from :ref:`Cover <config-cover>`. | ||
|
||
See :apiclass:`Cover <cover::Cover>` | ||
|
||
See Also | ||
-------- | ||
|
||
- :ghedit:`Edit` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
Custom Light Output | ||
=================== | ||
|
||
This integration can be used to create custom lights in ESPHome | ||
using the C++ (Arduino) API. | ||
|
||
Please first read :doc:`/components/sensor/custom` guide, | ||
the same principles apply here. | ||
|
||
All internal stuff (like effects, transitions etc) is handled by the light core | ||
and cannot be overriden. Light outputs are only responsible for displaying some state | ||
when asked to do so. | ||
|
||
The example below is an example of a custom light output. | ||
|
||
.. code-block:: cpp | ||
#include "esphome.h" | ||
class MyCustomLightOutput : public Component, public LightOutput { | ||
public: | ||
void setup() override { | ||
// This will be called by App.setup() | ||
pinMode(5, INPUT); | ||
} | ||
LightTraits get_traits() override { | ||
// return the traits this light supports | ||
auto traits = LightTraits(); | ||
traits.set_supports_brightness(true); | ||
traits.set_supports_rgb(true); | ||
traits.set_supports_rgb_white_value(false); | ||
traits.set_supports_color_temperature(false); | ||
return traits; | ||
} | ||
void write_state(LightState *state) override { | ||
// This will be called by the light to get a new state to be written. | ||
float red, green, blue; | ||
// use any of the provided current_values methods | ||
state->current_values_as_rgb(&red, &green, &blue); | ||
// Write red, green and blue to HW | ||
// ... | ||
} | ||
}; | ||
(Store this file in your configuration directory, for example ``my_light.h``) | ||
|
||
And in YAML: | ||
|
||
.. code-block:: yaml | ||
# Example configuration entry | ||
esphome: | ||
includes: | ||
- my_cover.h | ||
light: | ||
- platform: custom | ||
lambda: |- | ||
auto light_out = new MyCustomLightOutput(); | ||
App.register_component(light_out); | ||
return {light_out}; | ||
lights: | ||
- name: "My Custom Light" | ||
Configuration variables: | ||
|
||
- **lambda** (**Required**, :ref:`lambda <config-lambda>`): The lambda to run for instantiating the | ||
light output(s). | ||
- **lights** (**Required**, list): A list of lights to initialize. The length here | ||
must equal the number of items in the ``return`` statement of the ``lambda``. | ||
|
||
- All options from :ref:`Light <config-light>`. | ||
|
||
See :apiclass:`Light <light::LightOutput>` | ||
|
||
See Also | ||
-------- | ||
|
||
- :ghedit:`Edit` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters