custom-components / pyscript

Pyscript adds rich Python scripting to HASS
Apache License 2.0
873 stars 46 forks source link

Exception in <file.pv_excess_control.on_time> line 246 #590

Closed githuber110 closed 7 months ago

githuber110 commented 7 months ago

I have set up the blueprint according to the documentation, after running the automation I can see in the logbook that the script is triggered every 10 seconds, but nothing happens and the Appliance is not switched on although it should be based on the automation setup.

In the system log I see following error:

`This error originated from a custom integration.

Logger: custom_components.pyscript.file.pv_excess_control.on_time Source: custom_components/pyscript/trigger.py:1268 Integration: Pyscript Python scripting (documentation, issues) First occurred: March 1, 2024 at 23:50:21 (137 occurrences) Last logged: 00:13:01

Exception in line 246: first_item = next(iter(PvExcessControl.instances.values())) ^ RuntimeError: coroutine raised StopIteration`

Any idea what could be setup wrongly?

ALERTua commented 7 months ago

the setup is OK, but next() raises an exception due to no values found. I'd suggest assigning list(iter(PvExcessControl.instances.values())) to a variable, checking its length, and if it is not zero - then take the first element. The other way around is to catch StopIteration exception and pass it.

githuber110 commented 7 months ago

Thank you, will check that.