FEAT : Gestion du pzem
This commit is contained in:
parent
d20c1f5055
commit
c7b6ca42b3
71
config/tv.yaml
Normal file
71
config/tv.yaml
Normal file
@ -0,0 +1,71 @@
|
||||
esphome:
|
||||
name: tv
|
||||
friendly_name: TV
|
||||
|
||||
esp32:
|
||||
board: esp32-s3-devkitc-1
|
||||
framework:
|
||||
type: esp-idf
|
||||
|
||||
# Enable logging
|
||||
logger:
|
||||
|
||||
# Enable Home Assistant API
|
||||
api:
|
||||
encryption:
|
||||
key: "wbYIRZHpZb8Q8urkl1PqMfP54rY8TUca3VBJxx5DcmI="
|
||||
|
||||
ota:
|
||||
- platform: esphome
|
||||
password: "dbba6251c020b7547d3703b1fc8b5d9d"
|
||||
|
||||
wifi:
|
||||
ssid: !secret wifi_ssid
|
||||
password: !secret wifi_password
|
||||
|
||||
# Example configuration entry
|
||||
uart:
|
||||
tx_pin: GPIO44 # Il faut les inverser !!!!
|
||||
rx_pin: GPIO43
|
||||
baud_rate: 9600
|
||||
# debug:
|
||||
# direction: BOTH
|
||||
# dummy_receiver: false
|
||||
# after:
|
||||
# delimiter: "\n"
|
||||
# sequence:
|
||||
# - lambda: UARTDebug::log_string(direction, bytes);
|
||||
|
||||
modbus:
|
||||
|
||||
output:
|
||||
- platform: gpio
|
||||
pin: GPIO8
|
||||
id: gpio_8
|
||||
|
||||
sensor:
|
||||
- platform: pzemac
|
||||
address: 4
|
||||
power:
|
||||
name: "PZEM-004T V3 Power"
|
||||
on_value_range:
|
||||
- above: 2
|
||||
then:
|
||||
- lambda: |-
|
||||
// Convertir la valeur flottante en string
|
||||
char buffer[30]; // Taille suffisante pour stocker la chaîne
|
||||
snprintf(buffer, sizeof(buffer), "%.2f", x);
|
||||
ESP_LOGD("main", "--> Lampe ON (%s W)", buffer);
|
||||
id(gpio_8).turn_on();
|
||||
- below: 2
|
||||
then:
|
||||
- wait_until:
|
||||
condition:
|
||||
lambda: 'return millis() >= 60000;'
|
||||
- lambda: |-
|
||||
// Convertir la valeur flottante en string
|
||||
char buffer[30]; // Taille suffisante pour stocker la chaîne
|
||||
snprintf(buffer, sizeof(buffer), "%.2f", x);
|
||||
ESP_LOGD("main", "--> Lampe OFF (%s W)", buffer);
|
||||
id(gpio_8).turn_off();
|
||||
update_interval: 5s
|
||||
@ -1,6 +1,3 @@
|
||||
listener 1883
|
||||
protocol mqtt
|
||||
|
||||
listener 8883
|
||||
protocol mqtt
|
||||
cafile /mosquitto/config/ssl/mosquitto.crt
|
||||
|
||||
52
proto/pzem.py
Executable file
52
proto/pzem.py
Executable file
@ -0,0 +1,52 @@
|
||||
#!python
|
||||
# Importez les modules nécessaires de PyModbus
|
||||
from pymodbus.client import ModbusSerialClient
|
||||
import time
|
||||
from datetime import datetime
|
||||
|
||||
# Paramètres de communication série Modbus
|
||||
serial_port = "/dev/ttyUSB0"
|
||||
# Adresses Modbus des PZEM-OO4T
|
||||
pzems = [4]
|
||||
|
||||
|
||||
|
||||
# Main
|
||||
# Créez une instance du client Modbus
|
||||
client = ModbusSerialClient(port=serial_port, baudrate=9600, stopbits=1, bytesize=8, parity='N')
|
||||
# Ouvrez la connexion série
|
||||
client.connect()
|
||||
|
||||
while True:
|
||||
for pzem in pzems:
|
||||
print(f"PZEM : {pzem}")
|
||||
try:
|
||||
data = client.read_input_registers(0, 10, slave=pzem)
|
||||
if data:
|
||||
voltage = data.getRegister(0) / 10.0 # [V]
|
||||
current = (data.getRegister(1) + (data.getRegister(2) << 16)) / 1000.0 # [A]
|
||||
power = (data.getRegister(3) + (data.getRegister(4) << 16)) / 10.0 # [W]
|
||||
energy = data.getRegister(5) + (data.getRegister(6) << 16) # [Wh]
|
||||
frequency = data.getRegister(7) / 10.0 # [Hz]
|
||||
powerFactor = data.getRegister(8) / 100.0
|
||||
alarm = data.getRegister(9) # 0 = no alarm# La réponse contient les valeurs lues
|
||||
print("********************************")
|
||||
print("ID pince : " + str(pzem))
|
||||
print("Valeurs lues : " + str(data.registers))
|
||||
print('Voltage [V]: ', voltage)
|
||||
print('Current [A]: ', current)
|
||||
print('Power [W]: ', power) # active power (V * I * power factor)
|
||||
print('Energy [Wh]: ', energy)
|
||||
print('Frequency [Hz]: ', frequency)
|
||||
print('Power factor []: ', powerFactor)
|
||||
print('Alarm : ', alarm)
|
||||
else:
|
||||
maintenant = datetime.now()
|
||||
date_heure = maintenant.strftime("%Y-%m-%d %H:%M:%S")
|
||||
print(f"{date_heure} --> ERREUR : Aucune réponse.")
|
||||
except Exception as e:
|
||||
maintenant = datetime.now()
|
||||
date_heure = maintenant.strftime("%Y-%m-%d %H:%M:%S")
|
||||
print(f"{date_heure} --> ERREUR {e}")
|
||||
time.sleep(1)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user