Closed hubertgruber closed 2 years ago
I'll have a look at how to rewrite it to a better and more reproducable thing
Hi @hubertgruber - I recently moved everything and didn't realise not using the templating broke that way. I tried rewriting it already but there is a snag. It seems esphome / fan is not able to 'take' speed settings from something external.
I'll leave my rewrite of the esp yaml below - if you are only using the fan-component (i.e. skip setting high for 10/20/30 minutes etc.) and not have the intent to 'read' whatever the physical switches are sending you can get away with it.
The below code is based off having the custom switches as already included in the original version.
fan:
- platform: speed
speed_count: 3
output: mech_vent
name: "Mechanische ventilatie"
restore_mode: NO_RESTORE
on_turn_on:
- logger.log: "Fan Turned On, setting to 10min!"
- switch.turn_on: fansendt1
on_turn_off:
- logger.log: "Fan Turned Off, setting to low speed!"
- switch.turn_on: fansendlow
output:
- platform: template
id: mech_vent
type: float
write_action:
- if:
condition:
lambda: return ((state == 0));
then:
# action for off
- logger.log: "Fan set to low speed"
- switch.turn_on: fansendlow
- if:
condition:
lambda: return ((state > 0) && (state < .34));
then:
# action for low
- logger.log: "Fan set to low speed"
- switch.turn_on: fansendlow
- if:
condition:
lambda: return ((state > .34) && (state < .67));
then:
# action for medium
- logger.log: "Fan set to medium speed"
- switch.turn_on: fansendmedium
- if:
condition:
lambda: return ((state == 1));
then:
# action for high
- logger.log: "Fan set to high speed"
- switch.turn_on: fansendhigh
If it doesn't (re)build for you on homeassistant itself (using the esphome addon) - it works for me using this on the top
esphome:
name: {yournamehere}
platform: ESP8266
board: d1_mini_lite
libraries:
- SPI
- https://github.com/CoMPaTech/esphome_itho.git
- Ticker
includes:
- ITHO/fancontrol.h
Which - in less detail - is also what https://github.com/CoMPaTech/esphome_c1101_alt already does - so you might want to give that a spin as well
Thank you very much! I got it working on my system too! I had to remove the restore_mode
and add id's for the previously made custom switches, but it works like a charm again now! Here's my code for completeness:
esphome:
name: esp_atmega_itho_1
platform: ESP8266
board: nodemcuv2
includes:
- c1101.h
- ITHO/fancontrol.h
libraries:
- SPI
- https://github.com/CoMPaTech/esphome_itho.git
- Ticker
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
domain: xxsecretxx
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Esp Atmega Itho 1"
password: !secret backup_password
captive_portal:
# Enable logging
logger:
# Enable Home Assistant API
api:
password: !secret backup_password_2
ota:
password: !secret backup_password_2
switch:
- platform: custom
lambda: |-
auto fansendlow = new FanSendLow();
App.register_component(fansendlow);
return {fansendlow};
switches:
name: "FanSendLow"
id: fansendlow
- platform: custom
lambda: |-
auto fansendmedium = new FanSendMedium();
App.register_component(fansendmedium);
return {fansendmedium};
switches:
name: "FanSendMedium"
id: fansendmedium
- platform: custom
lambda: |-
auto fansendhigh = new FanSendHigh();
App.register_component(fansendhigh);
return {fansendhigh};
switches:
name: "FanSendHigh"
id: fansendhigh
- platform: custom
lambda: |-
auto fansendt1 = new FanSendIthoTimer1();
App.register_component(fansendt1);
return {fansendt1};
switches:
name: "FanSendTimer1"
id: fansendt1
- platform: custom
lambda: |-
auto fansendt2 = new FanSendIthoTimer2();
App.register_component(fansendt2);
return {fansendt2};
switches:
name: "FanSendTimer2"
id: fansendt2
- platform: custom
lambda: |-
auto fansendt3 = new FanSendIthoTimer3();
App.register_component(fansendt3);
return {fansendt3};
switches:
name: "FanSendTimer3"
id: fansendt3
- platform: custom
lambda: |-
auto fansendjoin = new FanSendIthoJoin();
App.register_component(fansendjoin);
return {fansendjoin};
switches:
name: "FanSendJoin"
id: fansendjoin
# Rinse/repeat for the timers
# see outstanding question in c1101.h
# on multiple switches handling
text_sensor:
- platform: custom
lambda: |-
auto fanrecv = new FanRecv();
App.register_component(fanrecv);
return {fanrecv->fanspeed,fanrecv->fantimer};
text_sensors:
- name: "FanSpeed"
- name: "FanTimer"
#### Fix for HA OS 2022.2
fan:
- platform: speed
speed_count: 3
output: mech_vent
name: "Bathroom fan"
# restore_mode: NO_RESTORE
on_turn_on:
- logger.log: "Fan Turned On, setting to 10min!"
- switch.turn_on: fansendt1
on_turn_off:
- logger.log: "Fan Turned Off, setting to low speed!"
- switch.turn_on: fansendlow
output:
- platform: template
id: mech_vent
type: float
write_action:
- if:
condition:
lambda: return ((state == 0));
then:
# action for off
- logger.log: "Fan set to low speed"
- switch.turn_on: fansendlow
- if:
condition:
lambda: return ((state > 0) && (state < .34));
then:
# action for low
- logger.log: "Fan set to low speed"
- switch.turn_on: fansendlow
- if:
condition:
lambda: return ((state > .34) && (state < .67));
then:
# action for medium
- logger.log: "Fan set to medium speed"
- switch.turn_on: fansendmedium
- if:
condition:
lambda: return ((state == 1));
then:
# action for high
- logger.log: "Fan set to high speed"
- switch.turn_on: fansendhigh
#### End fix for HA OS 2022.2
Closing because fan now works from HA OS 2022.2 onward with new code.
In Home Assistant 2022.2, the fan templating is broken, as there is now a requirement for a percentage. See https://developers.home-assistant.io/docs/core/entity/fan/#deprecated-properties.