Ok I will keep trying. I have set the time in the OS (Unraid) and it didn’t seem to fix it. I am assuming it is being set by the OS but I haven’t quite figured out where to change it.
i think this is a simular problem, maybe it helps you
I’m getting the same “UnboundLocalError: local variable ‘i’ referenced before assignment” error as @grangemd on attempted initialization of Occusim.
Reading through the chain and trying @ReneTode’s time comparison app, it looks like my problem is also clock-related. In my case, though, HA time is reported as “None”:
2018-09-27 17:47:19.584135 INFO time_check: 2018-09-27 17:47:19.584025
2018-09-27 17:47:19.585866 INFO time_check: None
2018-09-27 17:47:19.587048 INFO time_check: 2018-09-27 16:47:19.586914
The HA Time & Date sensor shows the correct local and UTC times in the HA frontend.
I’m running Hass.io with the 1.5 version of the community Appdaemon add-on. Any suggestions?
For others seeking to diagnose their errors, the typo-corrected version of the time comparison app follows. I also had to add “import appdaemon.plugins.hass.hassapi as hass”.
import appdaemon.plugins.hass.hassapi as hass
import datetime
class sound(hass.Hass):
def initialize(self):
localtime = datetime.datetime.now()
self.log(localtime)
hatime = self.get_state("sensor.date__time")
self.log(hatime)
utctime = datetime.datetime.utcnow()
self.log(utctime)
that you get None, means that you didnt configure that sensor (sensor.date__time) or it has another name.
in the dev section from HA frontend you can find the “states” section.
there you can lookup every entity that you have active in HA.
i didnt try to create a complete app, but just showed how to compare different times
for completeness you could also rename the class and add the yaml, but when someone has errors in AD i expect that they at least know how to create an app
also i am sure that the error isnt related to the time problem, but an configuration problem.
so please show me how you have configured occusim.
Thanks, Correct. I’d configured sensor.time & sensor.date but not sensor.date__time. Adding it results in the correct, matching time being shown across all three log entries. Still learning about HA and Appdaemon.
Fair enough!
Thanks for the offer. Here’s the config:
occupancy_simulator:
class: OccuSim
module: occusim
log: "1"
notify: "1"
enable: input_boolean.away,on
dump_times: "1"
reset_time: "02:00:00"
step_evening_name: Evening
step_evening_start: "sunset - 00:45:00"
step_evening_on_1: light.dining_room_pendants
step_evening_off_1: light.dining_room_pendants
step_evening_on_2: light.lower_stair_lights
step_evening_off_2: light.lower_stair_lights
step_night_name: Night
step_night_start: "23:59:00"
step_night_end: "sunrise"
random_livingroom_name: Evening Living Room
random_livingroom_start: Evening
random_livingroom_end: Night
random_livingroom_minduration: "00:14:00"
random_livingroom_maxduration: "00:31:00"
random_livingroom_number: "3"
random_livingroom_on_1: light.living_room_floor_lamp
random_livingroom_off_1: light.living_room_floor_lamp
random_guestroom_name: Evening Guest Room
random_guestroom_start: Evening
random_guestroom_end: Night
random_guestroom_minduration: "00:12:00"
random_guestroom_maxduration: "00:36:00"
random_guestroom_number: "3"
random_guestroom_on_1: light.guest_room_lights
random_guestroom_off_1: light.guest_room_lights
random_masterbedroom_name: Evening Master Bedroom
random_masterbedroom_start: Evening
random_masterbedroom_end: Night
random_masterbedroom_minduration: "00:14:00"
random_masterbedroom_maxduration: "00:31:00"
random_masterbedroom_number: "3"
random_masterbedroom_on_1: light.master_bedroom_lights
random_masterbedroom_off_1: light.master_bedroom_lights
Cheers!
oke i took a deeper look into the code from occusim, and it seems that its a small bug in the logging causing this error.
but i figured out what the problem is.
step_night_start: "23:59:00"
step_night_end: "sunrise"
as many programs occusim seems also to have problems with going from 1 day to the next.
start should always before the end, so if you change 23:59:00 to 00: 00: 01 your problem should be solved.
Thanks. I tried:
step_night_start: "23:59:00"
step_night_end: "sunrise"
But, that resulted in a different error:
2018-09-28 11:01:28.079802 INFO AppDaemon: Initializing app occupancy_simulator using class OccuSim from module occusim
2018-09-28 11:01:28.117319 WARNING AppDaemon: ------------------------------------------------------------
2018-09-28 11:01:28.118371 WARNING AppDaemon: Unexpected error running initialize() for occupancy_simulator
2018-09-28 11:01:28.119502 WARNING AppDaemon: ------------------------------------------------------------
2018-09-28 11:01:28.133537 WARNING AppDaemon: Traceback (most recent call last):
File "/usr/lib/python3.6/site-packages/appdaemon/appdaemon.py", line 1575, in init_object
init()
File "/config/appdaemon/apps/occusim.py", line 32, in initialize
self.create_events({})
File "/config/appdaemon/apps/occusim.py", line 177, in create_events
start = starttime + datetime.timedelta(seconds=random.randrange(tspan))
File "/usr/lib/python3.6/random.py", line 189, in randrange
raise ValueError("empty range for randrange()")
ValueError: empty range for randrange()
2018-09-28 11:01:28.134980 WARNING AppDaemon: ------------------------------------------------------------
2018-09-28 11:01:28.142445 INFO AppDaemon: App initialization complete
I can’t find the reference now, but I remember reading that OccuSim tasks must be complete before midnight. That’s why I originally had Night starting at 23:59:00.
You’re right that step_night_start and step_night_end are where the problem was. Thinking that maybe a time period like Night couldn’t cross or start after midnight, I changed Night to Midnight running from 23:59:00 to 23:59:59. That seems to work. The app now initializes without error. Now to see if it actually works tonight!
Here’s the updated config:
occupancy_simulator:
class: OccuSim
module: occusim
log: "1"
notify: "1"
enable: input_boolean.away,on
dump_times: "1"
reset_time: "02:00:00"
step_evening_name: Evening
step_evening_start: "sunset - 00:45:00"
step_evening_on_1: light.lower_stair_lights
step_evening_off_1: light.lower_stair_lights
step_midnight_name: Midnight
step_midnight_start: "23:59:00"
step_midnight_end: "23:59:59"
random_livingroom_name: Evening Living Room
random_livingroom_start: Evening
random_livingroom_end: Midnight
random_livingroom_minduration: "00:14:00"
random_livingroom_maxduration: "00:44:00"
random_livingroom_number: "4"
random_livingroom_on_1: light.living_room_floor_lamp
random_livingroom_off_1: light.living_room_floor_lamp
random_guestroom_name: Evening Guest Room
random_guestroom_start: Evening
random_guestroom_end: Midnight
random_guestroom_minduration: "00:12:00"
random_guestroom_maxduration: "00:36:00"
random_guestroom_number: "5"
random_guestroom_on_1: light.guest_room_lights
random_guestroom_off_1: light.guest_room_lights
random_masterbedroom_name: Evening Master Bedroom
random_masterbedroom_start: Evening
random_masterbedroom_end: Midnight
random_masterbedroom_minduration: "00:14:00"
random_masterbedroom_maxduration: "00:31:00"
random_masterbedroom_number: "3"
random_masterbedroom_on_1: light.master_bedroom_lights
random_masterbedroom_off_1: light.master_bedroom_lights
I think your issue is sunrise occurs before 23:59 of that day so it ends before it starts. It can’t work over 2 days so this is why 23:59:59 works