FEAT : Lecture HA
This commit is contained in:
parent
06a5672f52
commit
b2d458f637
17
main.py
17
main.py
@ -2,6 +2,7 @@ from machine import Pin, I2C, RTC
|
||||
import network
|
||||
import time
|
||||
import ntptime
|
||||
import urequests
|
||||
|
||||
led_jaune = Pin(0, Pin.OUT)
|
||||
led_bleue = Pin(2, Pin.OUT)
|
||||
@ -18,7 +19,9 @@ ntp_ttl = 3600
|
||||
ntp_attente = ntp_ttl
|
||||
rtc = RTC()
|
||||
|
||||
pas_temps = 1
|
||||
pas_temps = 30
|
||||
|
||||
token_ha = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJkNGY4MDdmYWYzNDQ0NTc0ODY4MmFmNzA4NDdmMTE0MyIsImlhdCI6MTc2NDQ1Mzk0NSwiZXhwIjoyMDc5ODEzOTQ1fQ.DJgSqeTKPHWbKEFH3HuFih4QKt3CSqLqot34_vhCOQU"
|
||||
|
||||
def button_jaune_presse(pin):
|
||||
print("Bouton jaune pressé !")
|
||||
@ -73,6 +76,17 @@ def ntp():
|
||||
print(f"Date et heure : {date_heure[3]}:{date_heure[4]}:{date_heure[5]} ({ntp_attente}, {HC()})")
|
||||
ntp_attente = ntp_attente - pas_temps
|
||||
|
||||
def charge() -> int:
|
||||
try:
|
||||
headers = {"Authorization": f"Bearer {token_ha}", "Content-Type": "application/json"}
|
||||
response = urequests.get("https://ha-demo.arbi.fr/api/states/sensor.zoe_batterie", headers=headers)
|
||||
data = response.json()
|
||||
response.close()
|
||||
return int(data["state"])
|
||||
except Exception as e:
|
||||
print("Erreur :", e)
|
||||
return -1
|
||||
|
||||
# Init
|
||||
set_relays(0b0000)
|
||||
led_jaune.off()
|
||||
@ -86,5 +100,6 @@ while True:
|
||||
# now = datetime.now()
|
||||
# print("Date et heure :", now)
|
||||
ntp()
|
||||
print(f"Charge : {charge()}")
|
||||
time.sleep(pas_temps)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user