Hello,
I didn't like managing valves as if they were lights, I also had difficulty using the output on automations.
So I rewrote the code as "number" in %.
See if it can be useful to others.
Code:
esphome:
name: miscelazione
friendly_name: miscelazione
on_boot:
priority: -10
then:
- output.set_level:
id: dac_valvola1
level: 1.0 # 100%
- output.set_level:
id: dac_valvola2
level: 0.7 # 70%
substitutions:
name: miscelazione
# Actions to set initial DAC values on boot
esp32:
board: esp32dev
framework:
type: arduino
# Enable logging
logger:
# Enable Home Assistant API
api:
encryption:
key: "xyxyxyxyyxy"
ota:
platform: esphome
password: "xyxyyxyxyxy4b"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Miscelazione Fallback Hotspot"
password: "xyxyxyxyyxyx"
captive_portal:
# Web server for diagnostics
web_server:
port: 80
# Sync time with Home Assistant
time:
- platform: homeassistant
id: homeassistant_time
sensor:
- platform: uptime
name: Miscelazione Uptime
- platform: wifi_signal
name: ${name} WiFi Signal
update_interval: 60s
device_class: signal_strength
unit_of_measurement: dB
output:
- platform: esp32_dac
pin: GPIO25
id: dac_valvola1
- platform: esp32_dac
pin: GPIO26
id: dac_valvola2
# Define custom components to represent the valves
number:
- platform: template
name: "Valvola Miscelatrice 1"
id: valvola1
min_value: 0.0
max_value: 100.0
step: 1.0
unit_of_measurement: '%'
icon: "mdi:valve"
optimistic: true
set_action:
then:
- output.set_level:
id: dac_valvola1
level: !lambda "return x / 100.0;"
initial_value: 100.0
- platform: template
name: "Valvola Miscelatrice 2"
id: valvola2
min_value: 0.0
max_value: 100.0
step: 1.0
unit_of_measurement: '%'
icon: "mdi:valve"
optimistic: true
set_action:
then:
- output.set_level:
id: dac_valvola2
level: !lambda "return x / 100.0;"
initial_value: 70.0
switch:
- platform: gpio
pin: GPIO02
name: "Pompa Piano 1"
icon: "mdi:pump"
id: relay1
- platform: gpio
pin: GPIO15
name: "Pompa Piano 2"
icon: "mdi:pump"
id: relay2