Hello, I am trying to implement a simple python script to control my lights during the lowest Nordpool prices.
The script works as expected in Jupyter Notebook from where the light can be controled. But the same script in Pyscript - HASS does not seem to work. I belive that everything is set up correctly, I manage to toggle on/off the light with the simple command:
#turn_on_light.py
entity_id = "light.matplats"
if entity_id is not None:
service_data = {"entity_id": entity_id}
hass.services.call("light", "turn_on", service_data, False)
And this is the code working in Jupyter but not in HASS:
# Turns off light when current price is one of the x highest today
dic = state.getattr('sensor.nordpool_kwh_se2_sek_3_10_025')
today = dic["today"]
today.sort(reverse = True)
number_of_hours = 10
highest = today[:number_of_hours]
if sensor.nordpool_kwh_se2_sek_3_10_025 in str(highest):
light.turn_on(entity_id="light.matplats")
else:
light.turn_off(entity_id="light.matplats")
Someone have any idea of whats going on?