Hi,
I’m relatively new to ESPhome but I have already successfully created some instances carrying out rather simple jobs.
Now, I’m wondering if I can implement something more elaborate/if it is possible in ESPhome?
I need to explain the background a bit more before I can ask my questions.
More than a decade ago I built a control for the ventilation of my basement. It is basically in two parts: an electronics box with an Atmega328 running a simple state machine which receives its instructions via a couple of cables from a raspi on which a python program runs the real “control software” (which also a state machine - but it’s much easier to make changes to a python program than to reflash the Atmega). I want to replace the python program by an automation in HA, but that’s not the question here.
The electronics box comprises the possibility to switch into an “independent”/“manual” mode where the very basic settings can be set using two switches having three states each. One controls three levels of “power”, the second allows to choose the fan directions (constantly a->b, constantly b->a or switching every few minutes between a->b and b->a). All in all, there are about 10 gpios to set depending on the state.
Now my question: I would like to replace the electronics box by a new one based on an ESP32 and ESPhome. Reading the two switches using ADC gpios is no problem. My idea was to use global variables and if “independent/manual” mode is chosen (using a switch), to evaluate these global variables in a state machine, preferably using the lambda framework. But here I’m struggling.
So far, I programmed my entities by reading the documentation, looking for examples, coding, getting errors, (jumping back to start) until it worked as I desired.
But here I don’t have an idea how (and where) to start or if it is doable at all.
Could anyone help me by providing some hints how and where I have to add this to the yaml?
Thanks in advance!
mabe
My yaml (with the necessary hardware definitions) looks at the moment like this:
globals:
- id: manual
type: bool
initial_value: "true"
- id: stufe
type: int
initial_value: '1'
- id: richtung
type: int # 0 = rot (Keller SO -> Werkstatt); 1 = Wechsel; 2 = grün (Werkstatt -> Keller SO)
initial_value: '1'
# All my outputs on the UI:
# three yellow LEDs indication the voltage levels: gb1, gb2, gb3
# the first one is always on => no GPIO necessary
# GPIOs 4, 5
# one output indication the direction: richtung
# GPIO 18
output:
- platform: gpio
pin: GPIO4
id: gb2
- platform: gpio
pin: GPIO5
id: gb3
- platform: gpio
pin: GPIO18
id: richtungsLED
# All my internal outputs:
# two for controlling the output voltage of the LM317
# GPIOs 25, 26
# two for driving the inner fan
# GPIOs 19, 22
# two for driving the outer fans
# GPIOs 21, 23
- platform: gpio
pin: GPIO25
id: lm317a
- platform: gpio
pin: GPIO26
id: lm317b
- platform: gpio
pin: GPIO19
id: innen_rt
- platform: gpio
pin: GPIO22
id: innen_gn
- platform: gpio
pin: GPIO21
id: aussen_rt
- platform: gpio
pin: GPIO23
id: aussen_gn
light:
- platform: binary
name: "LED Stufe 2"
output: gb2
- platform: binary
name: "LED Stufe 3"
output: gb3
- platform: binary
name: "LED Richtungsanzeige"
output: richtungsLED
# All my internal outputs:
# two for controlling the output voltage of the LM317
# GPIOs 25, 26
# two for driving the inner fan
# GPIOs 19, 22
# two for driving the outer fans
# GPIOs 21, 23
# perhaps only temporary for development
- platform: binary
name: "LM a"
output: lm317a
- platform: binary
name: "LM b"
output: lm317b
- platform: binary
name: "Innen gn"
output: innen_gn
- platform: binary
name: "Innen rt"
output: innen_rt
- platform: binary
name: "Aussen gn"
output: aussen_gn
- platform: binary
name: "Aussen rt"
output: aussen_rt
# My switches from the UI
# two three-way switches on analog inputs for direction and output voltage
# a binary switch to change between manual and auto
sensor:
- platform: adc
pin: GPIO32 #li
name: "Richtungswahl"
attenuation: auto
update_interval: 10s
on_value_range:
- below: 1.0
then:
- logger.log: "rot"
- globals.set:
id: richtung
value: "0"
- above: 1.0
below: 2.5
then:
- logger.log: "Wechsel"
- globals.set:
id: richtung
value: "1"
- above: 2.5
then:
- logger.log: "grün"
- globals.set:
id: richtung
value: "2"
- platform: adc
pin: GPIO35 #or
name: "Stufenwahl"
attenuation: auto
update_interval: 1s
on_value_range:
- below: 1.0
then:
- logger.log: "Stufe 1"
- globals.set:
id: stufe
value: "1"
# - output.turn_off: gb2
# - output.turn_off: gb3
- above: 1.0
below: 2.5
then:
- logger.log: "Stufe 2"
- globals.set:
id: stufe
value: "2"
# - output.turn_on: gb2
# - output.turn_off: gb3
- above: 2.5
then:
- logger.log: "Stufe 3"
- globals.set:
id: stufe
value: "3"
# - output.turn_on: gb2
# - output.turn_on: gb3
# It's always good to know the wifi strength
- platform: wifi_signal
name: "WiFi Signal Sensor"
update_interval: 60s
binary_sensor:
- platform: gpio
id: modeswitch
name: "Mode"
pin:
number: GPIO34 #bn
mode:
input: true
# pullup: true - external pullup since GPIO34 does not have an internal one
on_state:
then:
- if:
condition:
- binary_sensor.is_on: modeswitch
then:
- logger.log: "Jetzt manuell!"
- globals.set:
id: manual
value: "true"
else:
- logger.log: "automatisch"
- globals.set:
id: manual
value: "false"