I am getting this error when I try to use occusim. I have probably avoided it for awhile but I am trying to clean some things up here lately. I am on AppDaemon Version 3.0.1
Here is my error:
2018-09-13 14:53:44.505279 WARNING AppDaemon: Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/appdaemon/appdaemon.py", line 1575, in init_object
init()
File "/conf/apps/occusim.py", line 32, in initialize
self.create_events({})
File "/conf/apps/occusim.py", line 77, in create_events
self.log("step_{} end < start - ignoring end".format(i))
UnboundLocalError: local variable 'i' referenced before assignment
i dont know enough from occusim to see what might be wrong with this setup.
the best thing i think you can do is remove everything and test part by part.
1 thing i think can cause trouble.
using morning_off as name is not a good idea.
step_morning_off is part from the morning step
so i would at least change step_morning_off_off to step_morningoff_off
Ok I did as you suggested and started commenting out things until they worked. I am pretty sure it has to do with the sunrise and sunset items because when I change those to actual times it all works. I am guessing there is something wrong with how my longitude and latitude are set up within AD because I had to input this data into the appdaemon.yaml file manually for AD to work but also it has my sunset at about 23:55 tonight which is completely wrong for my location so I am guessing occusim is saying that some of my start times are after my end times so it errors out is my guess.
I was going to post my log files but my computer just crashed out on my so i will have to wait until i get home to reset it so that I can post the log files. Here is a link to an issue I filed awhile ago and if I didn’t have the longitude and latitude info my AD wouldn’t connect. I am not sure it will work with a local ip address but I can try it when i get home.
Ok if I take the longitude and latitude out of the appdaemon.yaml file it seems to work as long as I don’t have sunrise or sunset in the occusim file. It looks like my time is off by 4 hours in the log file though as I ran this a 17:13 not 21:13.
2018-09-14 21:13:31.319086 INFO AppDaemon Version 3.0.1 starting
2018-09-14 21:13:31.319276 INFO Configuration read from: /conf/appdaemon.yaml
2018-09-14 21:13:31.319996 INFO AppDaemon: Starting Apps
2018-09-14 21:13:31.321416 INFO AppDaemon: Loading Plugin HASS using class HassPlugin from module hassplugin
2018-09-14 21:13:31.326319 INFO AppDaemon: HASS: HASS Plugin Initializing
2018-09-14 21:13:31.326633 INFO AppDaemon: HASS: HASS Plugin initialization complete
2018-09-14 21:13:31.326805 INFO Dashboards are disabled
2018-09-14 21:13:31.326955 INFO API is disabled
2018-09-14 21:13:31.330716 INFO AppDaemon: HASS: Connected to Home Assistant 0.77.3
2018-09-14 21:13:31.360352 INFO AppDaemon: Got initial state from namespace default
2018-09-14 21:13:33.355403 INFO AppDaemon: Reading config
2018-09-14 21:13:33.365959 INFO AppDaemon: /conf/apps/apps.yaml added or modified
2018-09-14 21:13:33.366213 INFO AppDaemon: /conf/apps/apps.yaml added or modified
2018-09-14 21:13:33.366349 INFO AppDaemon: App 'Occupancy Simulator' added
2018-09-14 21:13:33.366468 INFO AppDaemon: App 'Switch Reset' added
2018-09-14 21:13:33.366739 INFO AppDaemon: Adding /conf/apps to module import path
2018-09-14 21:13:33.367318 WARNING AppDaemon: No app description found for: /conf/apps/globals.py - ignoring
2018-09-14 21:13:33.367453 INFO AppDaemon: Loading App Module: /conf/apps/occusim.py
2018-09-14 21:13:33.372999 INFO AppDaemon: Loading App Module: /conf/apps/switch_reset.py
2018-09-14 21:13:33.374041 INFO AppDaemon: Initializing app Occupancy Simulator using class OccuSim from module occusim
2018-09-14 21:13:33.405404 INFO Occupancy Simulator: Morning in the past - ignoring
2018-09-14 21:13:33.405946 INFO Occupancy Simulator: Morning Off in the past - ignoring
2018-09-14 21:13:33.406414 INFO Occupancy Simulator: Dinner Start in the past - ignoring
2018-09-14 21:13:33.406852 INFO Occupancy Simulator: Evening in the past - ignoring
2018-09-14 21:13:33.407261 INFO Occupancy Simulator: Kitchen_on_1 in the past - ignoring
2018-09-14 21:13:33.407660 INFO Occupancy Simulator: Kitchen_on_2 in the past - ignoring
2018-09-14 21:13:33.408074 INFO Occupancy Simulator: Kitchen_off_1 in the past - ignoring
2018-09-14 21:13:33.408480 INFO Occupancy Simulator: FrontRoom_on_2 in the past - ignoring
2018-09-14 21:13:33.408939 INFO Occupancy Simulator: Kitchen_off_2 in the past - ignoring
2018-09-14 21:13:33.409378 INFO Occupancy Simulator: FrontRoom_off_2 in the past - ignoring
2018-09-14 21:13:33.409792 INFO Occupancy Simulator: Living Room in the past - ignoring
2018-09-14 21:13:33.410245 INFO Occupancy Simulator: Kitchen_on_0 in the past - ignoring
2018-09-14 21:13:33.410708 INFO Occupancy Simulator: Kitchen_off_0 in the past - ignoring
2018-09-14 21:13:33.411177 INFO Occupancy Simulator: Dinner_on_0 in the past - ignoring
2018-09-14 21:13:33.411664 INFO Occupancy Simulator: Dinner_off_0 in the past - ignoring
2018-09-14 21:13:33.412170 INFO Occupancy Simulator: FrontRoom_on_1 in the past - ignoring
2018-09-14 21:13:33.412641 INFO Occupancy Simulator: TV in the past - ignoring
2018-09-14 21:13:33.413040 INFO Occupancy Simulator: Dinner End in the past - ignoring
2018-09-14 21:13:33.413490 INFO Occupancy Simulator: FrontRoom_off_1 in the past - ignoring
2018-09-14 21:13:33.413907 INFO Occupancy Simulator: FrontRoom_on_0 in the past - ignoring
2018-09-14 21:13:33.414322 INFO Occupancy Simulator: FrontRoom_off_0 in the past - ignoring
2018-09-14 21:13:33.414765 INFO Occupancy Simulator: Room Off: @ 2018-09-14 22:15:00
2018-09-14 21:13:33.415237 INFO Occupancy Simulator: TV Off: @ 2018-09-14 22:33:51
2018-09-14 21:13:33.427644 INFO Occupancy Simulator: Living Room Off: @ 2018-09-14 22:39:10
2018-09-14 21:13:33.427838 INFO AppDaemon: Initializing app Switch Reset using class SwitchReset from module switch_reset
2018-09-14 21:13:33.429943 INFO AppDaemon: App initialization complete
without that set in AD it should take the time from HA.
do you have time configured in HA, so that you can see time and date as a sensor, so that you can confirm that HA is running with the right time?
edit and did you configure longtitude, latitude and timezone in HA and how?
yes I confirmed my HA does output time and it is correct. Also my HA log shows the correct time as well.
Here is what I have for HA
homeassistant:
# Name of the location where Home Assistant is running
name: Granger New
# Location required to calculate the time the sun rises and sets
latitude: 39.76852
longitude: -86.15798
# Impacts weather/sunrise data (altitude above sea level in meters)
elevation: 274
# metric for Metric, imperial for Imperial
unit_system: imperial
# Pick yours from here: http://en.wikipedia.org/wiki/List_of_tz_database_time_zones
time_zone: America/Indiana/Indianapolis
just as i figured.
your datetime.now() gives the same as your datetime.utcnow()
that means that your device settings are set to utc
so the internal clock from your device is set to utc.
thats not something that can be helped inside AD.
the fact that HA shows the right time is because that is a recalculated time.
HA takes UTC time and recalculated that to local time.
but in AD you have to deal with plain python, and python takes the local time from the device.
so you have 2 options:
i think its more easy to find out how to change your device time. (its in the real device settings, not in a clock that you installed)
when you dont, your logs will always show wrong times