Skip to content

RuntimeError: no running event loop #753

@TheCarpetMerchant

Description

@TheCarpetMerchant

Just installed pyscript via HACS and added this script to the ~/pyscript folder using file editor :

@time_trigger("cron(*/15 * * * *)")
def water_heater():
  level = float(state.get("sensor.hyper_1_electric_level") or 0)

  if level > 98:
    log.info(f"Water Heater ON (level: {level})")
    task.executor(state.set, "light.water_heater_switch", "on")
  elif level < 80:
    log.info(f"Water Heater OFF (level: {level})")
    task.executor(state.set, "light.water_heater_switch", "off")
  else:
    # Check if the current charging speed of the batteries is more than what the water heater would consume.
    # We're only looking at one out of 2 batteries so take that into account
    if float(state.get("sensor.hyper_1_output_pack_power") or 0) > 300/2:
      log.info(f"Water Heater ON PV direct")
      task.executor(state.set, "light.water_heater_switch", "on")

(Yes I know, need to introduce a correct margin to prevent it flip-flopping, just trying to make it work for now).

This is the error I'm getting :

Exception in <file.water_heater.water_heater> line 10:         task.executor(state.set, "light.water_heater_switch", "off")                                                               ^ RuntimeError: no running event loop

Seems like something is completely wrong with the install, there's no event loop ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions