Hello everyone!
I need your help for my project which consists of automating the heating of my spa thanks to my solar thermal panel.
I made the code in Arduino IDE for my tests which works well.
The principle of the installation is a spa, a solar thermal panel. Each has a temperature probe, and depending on the temperatures collected, turn on or off the pump which circulates the water and therefore heats it or not.
This system is good, but I have no visual feedback of the data. So I would like to transform this .ino code into yaml to integrate it into EspHome of Home Assistant, first to see the temperatures and if the pump is running or not. Maybe after add a button to turn the pump on or off manually (2nd step that).
Here is my .ino code that works well:
#include <OneWire.h>
#include <DallasTemperature.h>
// Pin où les sondes DS18B20 sont connectées
const int ONE_WIRE_BUS = 4;
// Configuration du bus OneWire
OneWire oneWire(ONE_WIRE_BUS);
// Configuration du capteur Dallas Temperature
DallasTemperature sensors(&oneWire);
// Adresses des sondes détectées
DeviceAddress spaProbe = {0x28, 0x30, 0xA2, 0x6A, 0x00, 0x00, 0x00, 0xC8};
DeviceAddress panelProbe = {0x28, 0xDA, 0x86, 0x6C, 0x00, 0x00, 0x00, 0xC0};
// Pin de contrôle pour la pompe
const int POMPE_PIN = 2;
void setup() {
// Initialisation de la communication série
Serial.begin(115200);
Serial.println("Initialisation des sondes DS18B20...");
// Initialisation des capteurs
sensors.begin();
// Configuration de la pin de la pompe en sortie
pinMode(POMPE_PIN, OUTPUT);
digitalWrite(POMPE_PIN, LOW); // Assure que la pompe est éteinte au démarrage
}
void loop(void) {
// Demande de mise à jour des températures
sensors.requestTemperatures();
// Lecture des températures
float tempSpa = sensors.getTempC(spaProbe);
float tempPanel = sensors.getTempC(panelProbe);
// Affichage des températures
Serial.print("Température du spa : ");
Serial.print(tempSpa);
Serial.println(" °C");
Serial.print("Température du panneau solaire : ");
Serial.print(tempPanel);
Serial.println(" °C");
// Régulation de la pompe
if (tempPanel > tempSpa + 5 && tempSpa < 37) {
// Température du panneau solaire est suffisamment élevée et la température du spa est inférieure à 37°C
digitalWrite(POMPE_PIN, HIGH); // Activer la pompe
Serial.println("Pompe activée");
} else {
// Conditions non remplies
digitalWrite(POMPE_PIN, LOW); // Désactiver la pompe
Serial.println("Pompe désactivée");
}
// Attendre 5 secondes avant la prochaine lecture
delay(5000);
}
Here is my yaml code that does not work at all:
esphome:
name: solar-panel-spa
friendly_name: SOLAR-PANEL-SPA
esp32:
board: esp32dev
framework:
type: arduino
# Enable logging
logger:
# Enable Home Assistant API
api:
encryption:
key: "ojiPAfaSUemYjL3LjY7g3fy3ewxu9PZC6dv99voiCvI="
ota:
- platform: esphome
password: "233a44a993b4b60bdb652a156a6eae1e"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Solar-Panel-Spa Fallback Hotspot"
password: "1cHFnR3nhOQq"
captive_portal:
# Ajout des composants pour les capteurs DS18B20
one_wire:
- platform: gpio
pin: GPIO4
sensor:
- platform: dallas_temp
address: 0x2830A26A000000C8
name: "Température du spa"
- platform: dallas_temp
address: 0x28DA866C000000C0
name: "Température du panneau solaire"
# Configuration de la sortie pour la pompe
switch:
- platform: gpio
pin: GPIO2
name: "Pompe"
id: pompe
automation:
- trigger:
- platform: time
seconds: /5
condition:
- condition: and
conditions:
- condition: template
value_template: "{{ states('sensor.temperature_du_panneau_solaire')|float > states('sensor.temperature_du_spa')|float + 5 }}"
- condition: template
value_template: "{{ states('sensor.temperature_du_spa')|float < 37 }}"
action:
- switch.turn_on: pompe
- trigger:
- platform: time
seconds: /5
condition:
- condition: or
conditions:
- condition: template
value_template: "{{ states('sensor.temperature_du_panneau_solaire')|float <= states('sensor.temperature_du_spa')|float + 5 }}"
- condition: template
value_template: "{{ states('sensor.temperature_du_spa')|float >= 37 }}"
action:
- switch.turn_off: pompe
Thanks for your help, but maybe there is another way to do it than coding the yaml file.