Can I use an offset to sun_down and sun_up functions?

Trying to turn those lights on 1 hour before sun_down :grinning:

Thanks,

Tom

@ReneTode has a nice tutorial.

1 Like

Thanks for the link to @ReneTode - these are very helpful!

So I should have been more specific with my request - here’s the code snippet:

if (self.sun_down() or float(self.get_state(globals.illumination_garage)) < 25.0) and self.entities.switch.garage_inside_lights.state!= "on":
           self.turn_on("switch.garage_inside_lights")

Would be cool if I could somehow just do something like self.sun_down() - 1 to move it back an hour - but since self.sun_down() is actually returning a boolean, I guess not.

Thanks,

Tom

you want to use the self.run_at_sunset function for that.

or you want the self.now_is_between function.

even if self.sun_down would give back the sunset time you wouldnt have any use for it in a function.
a callback is triggered by a state change or by a timer.
it would need to be triggered exactly at the time you set in your callback to be true.

so i think you would like:

init(...):
  self.run_at_sunset(self.dosomething,offset= -3600)
def do something(...):
  if float(self.get_state(globals.illumination_garage)) < 25.0 and self.get_state(""switch.garage_inside_lights") != "on":
    self.turn_on("switch.garage_inside_lights")