esphome-docs/cookbook/ifan02.rst

214 lines
5.3 KiB
ReStructuredText
Raw Normal View History

ifan02 cookbook (#218) * ifan02 cookbook * removed spaces * removed spaces * indent codeblock, newline at end * fixes * add seo :image: * spaces... * Complete the example code & fix compilation errors Tried compiling this code today using ESPHome 1.13.6.. it would not compile. * The ifan02.h file was the main culprit and I was able to fix the issue. * The .yaml example was missing a few declarations at the beginning so I added them. * I fixed an error related to using ```light``` for the light id since that is a reserved name. * I added an ```on_boot``` declaration to turn off the light as early as possible after power is restored. (if mains power is restored in the middle of the night and the light turns on while you are sleeping it can be quite annoying, this turns it off during the boot process). * removed blank spaces on line 66 Those blank spaces get me every time ;-) * fix doc links (hopefully) I think my last PR was made against the wrong fork/branch/etc... sorry, I'm still learning github. I currently have the time and really want to see this make it into the cookbook. I think if you add me as a collaborator I would be able to push the changes and help get the errors sorted more quickly; if not, no worries, I'll take no offense and do my best to continue helping as we are doing now. * fix fan link replace ``` :doc:`/components/fan` ``` with ``` :doc:`/components/fan/index` ``` Co-authored-by: mjoshd <35782597+mjoshd@users.noreply.github.com> Co-authored-by: Guillermo Ruffino <glm.net@gmail.com>
2020-04-05 18:49:52 +02:00
Sonoff iFan02
=============
.. seo::
:description: Instructions for using Sonoff ifan02 in ESPHome.
:keywords: Fan, Sonoff, ifan02
:image: fan.svg
Sonoff iFan02 is a driver for ceiling fans with lights.
By replacing the old driver with iFan02, your non-smart led ceiling fan will be converted to a smart ceiling fan.
For more information see `iFan02 <https://www.itead.cc/sonoff-ifan02-wifi-smart-ceiling-fan-with-light.html>`__
This configuration will expose a :doc:`/components/light/binary` and a :doc:`/components/fan/speed`.
To get this working in ESPHome you first need to create a :doc:`/components/output/custom` to control the iFan02.
2021-01-11 17:46:37 +01:00
Create an ifan02.h file:
ifan02 cookbook (#218) * ifan02 cookbook * removed spaces * removed spaces * indent codeblock, newline at end * fixes * add seo :image: * spaces... * Complete the example code & fix compilation errors Tried compiling this code today using ESPHome 1.13.6.. it would not compile. * The ifan02.h file was the main culprit and I was able to fix the issue. * The .yaml example was missing a few declarations at the beginning so I added them. * I fixed an error related to using ```light``` for the light id since that is a reserved name. * I added an ```on_boot``` declaration to turn off the light as early as possible after power is restored. (if mains power is restored in the middle of the night and the light turns on while you are sleeping it can be quite annoying, this turns it off during the boot process). * removed blank spaces on line 66 Those blank spaces get me every time ;-) * fix doc links (hopefully) I think my last PR was made against the wrong fork/branch/etc... sorry, I'm still learning github. I currently have the time and really want to see this make it into the cookbook. I think if you add me as a collaborator I would be able to push the changes and help get the errors sorted more quickly; if not, no worries, I'll take no offense and do my best to continue helping as we are doing now. * fix fan link replace ``` :doc:`/components/fan` ``` with ``` :doc:`/components/fan/index` ``` Co-authored-by: mjoshd <35782597+mjoshd@users.noreply.github.com> Co-authored-by: Guillermo Ruffino <glm.net@gmail.com>
2020-04-05 18:49:52 +02:00
.. code-block:: c++
#include "esphome.h"
using namespace esphome;
class IFan02Output : public Component, public FloatOutput {
public:
void write_state(float state) override {
if (state < 0.3) {
// OFF
digitalWrite(5, LOW);
digitalWrite(4, LOW);
digitalWrite(15, LOW);
} else if (state < 0.6) {
// low speed
digitalWrite(5, HIGH);
digitalWrite(4, LOW);
digitalWrite(15, LOW);
} else if (state < 0.9) {
// medium speed
digitalWrite(5, HIGH);
digitalWrite(4, HIGH);
digitalWrite(15, LOW);
} else {
// high speed
digitalWrite(5, HIGH);
digitalWrite(4, LOW);
digitalWrite(15, HIGH);
}
}
};
Then you need to set it up with yaml.
.. code-block:: yaml
esphome:
name: ifan02
platform: ESP8266
board: esp8285
includes:
- ifan02.h
on_boot:
priority: 225
# turn off the light as early as possible
then:
- light.turn_off: ifan02_light
wifi:
ssid: <YOUR_SSID>
password: <YOUR_PASSWORD>
api:
logger:
ota:
binary_sensor:
- platform: gpio
id: vbutton_light
pin:
number: GPIO0
inverted: true
ifan02 cookbook (#218) * ifan02 cookbook * removed spaces * removed spaces * indent codeblock, newline at end * fixes * add seo :image: * spaces... * Complete the example code & fix compilation errors Tried compiling this code today using ESPHome 1.13.6.. it would not compile. * The ifan02.h file was the main culprit and I was able to fix the issue. * The .yaml example was missing a few declarations at the beginning so I added them. * I fixed an error related to using ```light``` for the light id since that is a reserved name. * I added an ```on_boot``` declaration to turn off the light as early as possible after power is restored. (if mains power is restored in the middle of the night and the light turns on while you are sleeping it can be quite annoying, this turns it off during the boot process). * removed blank spaces on line 66 Those blank spaces get me every time ;-) * fix doc links (hopefully) I think my last PR was made against the wrong fork/branch/etc... sorry, I'm still learning github. I currently have the time and really want to see this make it into the cookbook. I think if you add me as a collaborator I would be able to push the changes and help get the errors sorted more quickly; if not, no worries, I'll take no offense and do my best to continue helping as we are doing now. * fix fan link replace ``` :doc:`/components/fan` ``` with ``` :doc:`/components/fan/index` ``` Co-authored-by: mjoshd <35782597+mjoshd@users.noreply.github.com> Co-authored-by: Guillermo Ruffino <glm.net@gmail.com>
2020-04-05 18:49:52 +02:00
on_press:
then:
- light.toggle: ifan02_light
- platform: gpio
id: vbutton_relay_1
pin:
number: GPIO9
inverted: true
ifan02 cookbook (#218) * ifan02 cookbook * removed spaces * removed spaces * indent codeblock, newline at end * fixes * add seo :image: * spaces... * Complete the example code & fix compilation errors Tried compiling this code today using ESPHome 1.13.6.. it would not compile. * The ifan02.h file was the main culprit and I was able to fix the issue. * The .yaml example was missing a few declarations at the beginning so I added them. * I fixed an error related to using ```light``` for the light id since that is a reserved name. * I added an ```on_boot``` declaration to turn off the light as early as possible after power is restored. (if mains power is restored in the middle of the night and the light turns on while you are sleeping it can be quite annoying, this turns it off during the boot process). * removed blank spaces on line 66 Those blank spaces get me every time ;-) * fix doc links (hopefully) I think my last PR was made against the wrong fork/branch/etc... sorry, I'm still learning github. I currently have the time and really want to see this make it into the cookbook. I think if you add me as a collaborator I would be able to push the changes and help get the errors sorted more quickly; if not, no worries, I'll take no offense and do my best to continue helping as we are doing now. * fix fan link replace ``` :doc:`/components/fan` ``` with ``` :doc:`/components/fan/index` ``` Co-authored-by: mjoshd <35782597+mjoshd@users.noreply.github.com> Co-authored-by: Guillermo Ruffino <glm.net@gmail.com>
2020-04-05 18:49:52 +02:00
on_press:
then:
- switch.toggle: fan_relay1
- switch.turn_on: update_fan_speed
- platform: gpio
id: vbutton_relay_2
pin:
number: GPIO10
inverted: true
ifan02 cookbook (#218) * ifan02 cookbook * removed spaces * removed spaces * indent codeblock, newline at end * fixes * add seo :image: * spaces... * Complete the example code & fix compilation errors Tried compiling this code today using ESPHome 1.13.6.. it would not compile. * The ifan02.h file was the main culprit and I was able to fix the issue. * The .yaml example was missing a few declarations at the beginning so I added them. * I fixed an error related to using ```light``` for the light id since that is a reserved name. * I added an ```on_boot``` declaration to turn off the light as early as possible after power is restored. (if mains power is restored in the middle of the night and the light turns on while you are sleeping it can be quite annoying, this turns it off during the boot process). * removed blank spaces on line 66 Those blank spaces get me every time ;-) * fix doc links (hopefully) I think my last PR was made against the wrong fork/branch/etc... sorry, I'm still learning github. I currently have the time and really want to see this make it into the cookbook. I think if you add me as a collaborator I would be able to push the changes and help get the errors sorted more quickly; if not, no worries, I'll take no offense and do my best to continue helping as we are doing now. * fix fan link replace ``` :doc:`/components/fan` ``` with ``` :doc:`/components/fan/index` ``` Co-authored-by: mjoshd <35782597+mjoshd@users.noreply.github.com> Co-authored-by: Guillermo Ruffino <glm.net@gmail.com>
2020-04-05 18:49:52 +02:00
on_press:
then:
- switch.toggle: fan_relay2
- switch.turn_on: update_fan_speed
- platform: gpio
id: vbutton_relay_3
pin:
number: GPIO14
inverted: true
ifan02 cookbook (#218) * ifan02 cookbook * removed spaces * removed spaces * indent codeblock, newline at end * fixes * add seo :image: * spaces... * Complete the example code & fix compilation errors Tried compiling this code today using ESPHome 1.13.6.. it would not compile. * The ifan02.h file was the main culprit and I was able to fix the issue. * The .yaml example was missing a few declarations at the beginning so I added them. * I fixed an error related to using ```light``` for the light id since that is a reserved name. * I added an ```on_boot``` declaration to turn off the light as early as possible after power is restored. (if mains power is restored in the middle of the night and the light turns on while you are sleeping it can be quite annoying, this turns it off during the boot process). * removed blank spaces on line 66 Those blank spaces get me every time ;-) * fix doc links (hopefully) I think my last PR was made against the wrong fork/branch/etc... sorry, I'm still learning github. I currently have the time and really want to see this make it into the cookbook. I think if you add me as a collaborator I would be able to push the changes and help get the errors sorted more quickly; if not, no worries, I'll take no offense and do my best to continue helping as we are doing now. * fix fan link replace ``` :doc:`/components/fan` ``` with ``` :doc:`/components/fan/index` ``` Co-authored-by: mjoshd <35782597+mjoshd@users.noreply.github.com> Co-authored-by: Guillermo Ruffino <glm.net@gmail.com>
2020-04-05 18:49:52 +02:00
on_press:
then:
- switch.toggle: fan_relay3
- switch.turn_on: update_fan_speed
output:
- platform: custom
type: float
outputs:
id: fanoutput
lambda: |-
auto ifan02_fan = new IFan02Output();
App.register_component(ifan02_fan);
return {ifan02_fan};
- platform: gpio
pin: GPIO12
id: light_output
light:
- platform: binary
name: "iFan02 Light"
output: light_output
id: ifan02_light
switch:
- platform: template
id: update_fan_speed
optimistic: true
ifan02 cookbook (#218) * ifan02 cookbook * removed spaces * removed spaces * indent codeblock, newline at end * fixes * add seo :image: * spaces... * Complete the example code & fix compilation errors Tried compiling this code today using ESPHome 1.13.6.. it would not compile. * The ifan02.h file was the main culprit and I was able to fix the issue. * The .yaml example was missing a few declarations at the beginning so I added them. * I fixed an error related to using ```light``` for the light id since that is a reserved name. * I added an ```on_boot``` declaration to turn off the light as early as possible after power is restored. (if mains power is restored in the middle of the night and the light turns on while you are sleeping it can be quite annoying, this turns it off during the boot process). * removed blank spaces on line 66 Those blank spaces get me every time ;-) * fix doc links (hopefully) I think my last PR was made against the wrong fork/branch/etc... sorry, I'm still learning github. I currently have the time and really want to see this make it into the cookbook. I think if you add me as a collaborator I would be able to push the changes and help get the errors sorted more quickly; if not, no worries, I'll take no offense and do my best to continue helping as we are doing now. * fix fan link replace ``` :doc:`/components/fan` ``` with ``` :doc:`/components/fan/index` ``` Co-authored-by: mjoshd <35782597+mjoshd@users.noreply.github.com> Co-authored-by: Guillermo Ruffino <glm.net@gmail.com>
2020-04-05 18:49:52 +02:00
turn_on_action:
then:
- delay: 200ms
- if:
condition:
and:
- switch.is_off: fan_relay1
- switch.is_off: fan_relay2
- switch.is_off: fan_relay3
then:
- fan.turn_off: ifan02_fan
- if:
condition:
and:
- switch.is_on: fan_relay1
- switch.is_off: fan_relay2
- switch.is_off: fan_relay3
then:
- fan.turn_on:
id: ifan02_fan
speed: 1
ifan02 cookbook (#218) * ifan02 cookbook * removed spaces * removed spaces * indent codeblock, newline at end * fixes * add seo :image: * spaces... * Complete the example code & fix compilation errors Tried compiling this code today using ESPHome 1.13.6.. it would not compile. * The ifan02.h file was the main culprit and I was able to fix the issue. * The .yaml example was missing a few declarations at the beginning so I added them. * I fixed an error related to using ```light``` for the light id since that is a reserved name. * I added an ```on_boot``` declaration to turn off the light as early as possible after power is restored. (if mains power is restored in the middle of the night and the light turns on while you are sleeping it can be quite annoying, this turns it off during the boot process). * removed blank spaces on line 66 Those blank spaces get me every time ;-) * fix doc links (hopefully) I think my last PR was made against the wrong fork/branch/etc... sorry, I'm still learning github. I currently have the time and really want to see this make it into the cookbook. I think if you add me as a collaborator I would be able to push the changes and help get the errors sorted more quickly; if not, no worries, I'll take no offense and do my best to continue helping as we are doing now. * fix fan link replace ``` :doc:`/components/fan` ``` with ``` :doc:`/components/fan/index` ``` Co-authored-by: mjoshd <35782597+mjoshd@users.noreply.github.com> Co-authored-by: Guillermo Ruffino <glm.net@gmail.com>
2020-04-05 18:49:52 +02:00
- if:
condition:
and:
- switch.is_on: fan_relay1
- switch.is_on: fan_relay2
- switch.is_off: fan_relay3
then:
- fan.turn_on:
id: ifan02_fan
speed: 2
ifan02 cookbook (#218) * ifan02 cookbook * removed spaces * removed spaces * indent codeblock, newline at end * fixes * add seo :image: * spaces... * Complete the example code & fix compilation errors Tried compiling this code today using ESPHome 1.13.6.. it would not compile. * The ifan02.h file was the main culprit and I was able to fix the issue. * The .yaml example was missing a few declarations at the beginning so I added them. * I fixed an error related to using ```light``` for the light id since that is a reserved name. * I added an ```on_boot``` declaration to turn off the light as early as possible after power is restored. (if mains power is restored in the middle of the night and the light turns on while you are sleeping it can be quite annoying, this turns it off during the boot process). * removed blank spaces on line 66 Those blank spaces get me every time ;-) * fix doc links (hopefully) I think my last PR was made against the wrong fork/branch/etc... sorry, I'm still learning github. I currently have the time and really want to see this make it into the cookbook. I think if you add me as a collaborator I would be able to push the changes and help get the errors sorted more quickly; if not, no worries, I'll take no offense and do my best to continue helping as we are doing now. * fix fan link replace ``` :doc:`/components/fan` ``` with ``` :doc:`/components/fan/index` ``` Co-authored-by: mjoshd <35782597+mjoshd@users.noreply.github.com> Co-authored-by: Guillermo Ruffino <glm.net@gmail.com>
2020-04-05 18:49:52 +02:00
- if:
condition:
and:
- switch.is_on: fan_relay1
- switch.is_off: fan_relay2
- switch.is_on: fan_relay3
then:
- fan.turn_on:
id: ifan02_fan
speed: 3
ifan02 cookbook (#218) * ifan02 cookbook * removed spaces * removed spaces * indent codeblock, newline at end * fixes * add seo :image: * spaces... * Complete the example code & fix compilation errors Tried compiling this code today using ESPHome 1.13.6.. it would not compile. * The ifan02.h file was the main culprit and I was able to fix the issue. * The .yaml example was missing a few declarations at the beginning so I added them. * I fixed an error related to using ```light``` for the light id since that is a reserved name. * I added an ```on_boot``` declaration to turn off the light as early as possible after power is restored. (if mains power is restored in the middle of the night and the light turns on while you are sleeping it can be quite annoying, this turns it off during the boot process). * removed blank spaces on line 66 Those blank spaces get me every time ;-) * fix doc links (hopefully) I think my last PR was made against the wrong fork/branch/etc... sorry, I'm still learning github. I currently have the time and really want to see this make it into the cookbook. I think if you add me as a collaborator I would be able to push the changes and help get the errors sorted more quickly; if not, no worries, I'll take no offense and do my best to continue helping as we are doing now. * fix fan link replace ``` :doc:`/components/fan` ``` with ``` :doc:`/components/fan/index` ``` Co-authored-by: mjoshd <35782597+mjoshd@users.noreply.github.com> Co-authored-by: Guillermo Ruffino <glm.net@gmail.com>
2020-04-05 18:49:52 +02:00
- switch.turn_off: update_fan_speed
- platform: gpio
pin: GPIO5
id: fan_relay1
- platform: gpio
pin: GPIO4
id: fan_relay2
- platform: gpio
pin: GPIO15
id: fan_relay3
fan:
- platform: speed
output: fanoutput
id: ifan02_fan
speed_count: 3
ifan02 cookbook (#218) * ifan02 cookbook * removed spaces * removed spaces * indent codeblock, newline at end * fixes * add seo :image: * spaces... * Complete the example code & fix compilation errors Tried compiling this code today using ESPHome 1.13.6.. it would not compile. * The ifan02.h file was the main culprit and I was able to fix the issue. * The .yaml example was missing a few declarations at the beginning so I added them. * I fixed an error related to using ```light``` for the light id since that is a reserved name. * I added an ```on_boot``` declaration to turn off the light as early as possible after power is restored. (if mains power is restored in the middle of the night and the light turns on while you are sleeping it can be quite annoying, this turns it off during the boot process). * removed blank spaces on line 66 Those blank spaces get me every time ;-) * fix doc links (hopefully) I think my last PR was made against the wrong fork/branch/etc... sorry, I'm still learning github. I currently have the time and really want to see this make it into the cookbook. I think if you add me as a collaborator I would be able to push the changes and help get the errors sorted more quickly; if not, no worries, I'll take no offense and do my best to continue helping as we are doing now. * fix fan link replace ``` :doc:`/components/fan` ``` with ``` :doc:`/components/fan/index` ``` Co-authored-by: mjoshd <35782597+mjoshd@users.noreply.github.com> Co-authored-by: Guillermo Ruffino <glm.net@gmail.com>
2020-04-05 18:49:52 +02:00
name: "iFan02 Fan"
See Also
--------
- :doc:`/components/light/index`
- :doc:`/components/light/binary`
- :doc:`/components/fan/index`
- :doc:`/components/fan/speed`
- :doc:`/components/output/index`
- :doc:`/components/output/custom`
- :doc:`/guides/automations`
- :ghedit:`Edit`