takéto niečo (je to na tuya zásuvky z aliexpress, tých mám plno):
import requests
import json
from bs4 import BeautifulSoup
import tinytuya
import time
device_id = "........................"
local_key = "......................."
ip_address="192.168...."
d = tinytuya.OutletDevice(device_id, ip_address, local_key)
d.set_version(3.3)
data = d.status()
zapnute=data['dps']['1']
# Show status and state of first controlled switch on device
#print('Dictionary %r' % data)
#print(data)
url = "http://192.168.5.108"
page = requests.get(url)
soup = BeautifulSoup(page.content, "html.parser")
for tr in soup.find_all('tr'):
th = tr.find('th')
if th and th.text.strip() == 'L1:':
td = tr.find('td')
if td:
l1_value = td.text.strip().split(' ')[0]
if th and th.text.strip() == 'L2:':
td = tr.find('td')
if td:
l2_value = td.text.strip().split(' ')[0]
if th and th.text.strip() == 'L3:':
td = tr.find('td')
if td:
l3_value = td.text.strip().split(' ')[0]
if th and th.text.strip() == 'Charge Current:':
td = tr.find('td')
if td:
nabijanie = td.text.strip().split(' ')[0]
l1= float(l1_value[:-1].replace(" ", ""))
l2= float(l2_value[:-1].replace(" ", ""))
l3= float(l2_value[:-1].replace(" ", ""))
nabija = float(nabijanie[:-1].replace(" ", ""))
prud=l1+l2+l3
print(prud,zapnute,nabija)
if zapnute == True and (prud>0 or time.localtime()[3]<9 or time.localtime()[3]>18):
d.turn_off()
print("Vypínam ohrev vody")
if zapnute == False and (prud<-10 or nabija>10) and time.localtime()[3]>8 and time.localtime()[3]<19:
d.turn_on()
print("Zapínam ohrev vody")
import requests
import json
from bs4 import BeautifulSoup
import tinytuya
import time
device_id = "........................"
local_key = "......................."
ip_address="192.168...."
d = tinytuya.OutletDevice(device_id, ip_address, local_key)
d.set_version(3.3)
data = d.status()
zapnute=data['dps']['1']
# Show status and state of first controlled switch on device
#print('Dictionary %r' % data)
#print(data)
url = "http://192.168.5.108"
page = requests.get(url)
soup = BeautifulSoup(page.content, "html.parser")
for tr in soup.find_all('tr'):
th = tr.find('th')
if th and th.text.strip() == 'L1:':
td = tr.find('td')
if td:
l1_value = td.text.strip().split(' ')[0]
if th and th.text.strip() == 'L2:':
td = tr.find('td')
if td:
l2_value = td.text.strip().split(' ')[0]
if th and th.text.strip() == 'L3:':
td = tr.find('td')
if td:
l3_value = td.text.strip().split(' ')[0]
if th and th.text.strip() == 'Charge Current:':
td = tr.find('td')
if td:
nabijanie = td.text.strip().split(' ')[0]
l1= float(l1_value[:-1].replace(" ", ""))
l2= float(l2_value[:-1].replace(" ", ""))
l3= float(l2_value[:-1].replace(" ", ""))
nabija = float(nabijanie[:-1].replace(" ", ""))
prud=l1+l2+l3
print(prud,zapnute,nabija)
if zapnute == True and (prud>0 or time.localtime()[3]<9 or time.localtime()[3]>18):
d.turn_off()
print("Vypínam ohrev vody")
if zapnute == False and (prud<-10 or nabija>10) and time.localtime()[3]>8 and time.localtime()[3]<19:
d.turn_on()
print("Zapínam ohrev vody")
Komentár