Occusim Randrange issue?

I’m getting the below error on Appdaemon. Running 3.0.1.

2018-06-17 08:02:55.647877 INFO AppDaemon: Initializing app Occupancy Simulator using class OccuSim from module occusim
2018-06-17 08:02:55.668607 WARNING AppDaemon: ------------------------------------------------------------
2018-06-17 08:02:55.669251 WARNING AppDaemon: Unexpected error running initialize() for Occupancy Simulator
2018-06-17 08:02:55.669845 WARNING AppDaemon: ------------------------------------------------------------
2018-06-17 08:02:55.672251 WARNING AppDaemon: Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/appdaemon/appdaemon.py", line 1575, in init_object
    init()
  File "/home/homeassistant/.homeassistant/apps/occusim.py", line 32, in initialize
    self.create_events({})
  File "/home/homeassistant/.homeassistant/apps/occusim.py", line 177, in create_events
    start = starttime + datetime.timedelta(seconds=random.randrange(tspan))
  File "/usr/lib/python3.5/random.py", line 195, in randrange
    raise ValueError("empty range for randrange()")
ValueError: empty range for randrange()

2018-06-17 08:02:55.673068 WARNING AppDaemon: ----------------------------------

Here’s my config for occusim:

######
### Weekday Morning Routine
######

  step_weekday_morning_on_name: Weekday Morning On
  step_weekday_morning_on_start: "06:00:00"
  step_weekday_morning_on_days: mon,tue,wed,thu,fri
  step_weekday_morning_on_on_1: scene.morning

  step_weekday_morning_off_name: Weekday Morning Off
  step_weekday_morning_off_start: "sunrise + 00:45:00"
  step_weekday_morning_off_days: mon,tue,wed,thu,fri
  step_weekday_morning_off_end: "sunrise + 01:00:00"
  step_weekday_morning_off_on_1: scene.house_off

######
### Weekend Morning Routine
######

  step_weekend_morning_on_name: Weekend Morning On
  step_weekend_morning_on_start: "06:45:00"
  step_weekend_morning_on_days: sat,sun
  step_weekend_morning_on_end: "07:45:00"
  step_weekend_morning_on_on_1: scene.morning

  step_weekend_morning_off_name: Weekend Morning Off
  step_weekend_morning_off_start: "sunrise + 01:05:00"
  step_weekend_morning_off_days: sat, sun
  step_weekend_morning_off_end: "sunrise + 01:25:00"
  step_weekend_morning_off_on_1: scene.house_off

######
### Evening Routine
######

  step_evening_on_name: Evening First Floor On
  step_evening_on_start: "sunset + 00:05:00"
  step_evening_on_end: "sunset + 01:00:00"
  step_evening_on_on_1: scene.morning

  step_evening_upstairs_on_name: Evening Upstairs On
  step_evening_upstairs_on_relative: Evening First Floor On
  step_evening_upstairs_on_start_offset: "00:30:00"
  step_evening_upstairs_on_end_offset: "00:55:00"
  step_evening_upstairs_on_on_1: scene.upstairs_on

  step_evening_basement_on_name: Evening Basement On
  step_evening_basement_on_relative: Evening First Floor On
  step_evening_basement_on_start_offset: "00:30:00"
  step_evening_basement_on_end_offset: "00:55:00"
  step_evening_basement_on_on_1: scene.basement_on

  random_first_floor_name: Random First Floor
  random_first_floor_start: Evening First Floor On
  random_first_floor_end: Bedtime
  random_first_floor_minduration: "00:45:00"
  random_first_floor_maxduration: "01:15:00"
  random_first_floor_number: 5
  random_first_floor_on_1: switch.kitchen_switch
  random_first_floor_off_1: switch.kitchen_switch
  random_first_floor_on_2: light.family_room
  random_first_floor_off_2: light.family_room
  random_first_floor_on_3: light.entry_level
  random_first_floor_off_3: light.entry_level

  random_basement_name: Random Basement
  random_basement_start: Evening Basement On
  random_basement_end: Bedtime
  random_basement_minduration: "00:45:00"
  random_basement_maxduration: "01:15:00"
  random_basement_number: 5
  random_basement_on_1: light.basement
  random_basement_off_1: light.basement
  random_basement_on_2: light.basement_staircase_level
  random_basement_off_2: light.basement_staircase_level

  random_upstairs_name: Random Upstairs
  random_upstairs_start: Evening Upstairs On
  random_upstairs_end: Bedtime
  random_upstairs_minduration: "00:45:00"
  random_upstairs_maxduration: "01:15:00"
  random_upstairs_number: 5
  random_upstairs_on_1: light.master_bedroom
  random_upstairs_off_1: light.master_bedroom
  random_upstairs_on_2: light.upstairs_staircase_level
  random_upstairs_off_2: light.upstairs_staircase_level
  random_upstairs_on_3: light.nursery
  random_upstairs_off_3: light.nursery

######
### Bedtime
######

  step_bedtime_name: Bedtime
  step_bedtime_start: "21:00:00"
  step_bedtime_end: "22:15:00"
  step_bedtime_on_1: scene.house_off

I’m guessing it’s something obvious I’m missing but can’t spot it.

i never used occusim, but your error is because a random is empty.

you have:

random_first_floor_number: 5
random_basement_number: 5
random_upstairs_number: 5

and my gut tells me that that number should be the amount of lights.
and you use only 2 or 3 lights, so that leaves several lights empty.

The 5 is for how many times to turn on/off: https://github.com/acockburn/occusim#random-operation

random_<random_name>_number - Number of times within the period to fire the event

So that’s not it I don’t think.

yeah your right.

then i dont see it either and i need to call @aimc for that.

Try putting the names of the steps in quotes e.g. “Evening Basement On” - YAML does funny things with things like Off and On - it tries to interpret them as true and false and that may be causing issues. The line in the code that has the error points to a problem with the identification of the start step or end step for one of the random clauses, and that may explain it.

1 Like

Not seeing any errors atm, will see if that works, thanks @aimc !

Sigh. Spoke too soon. Didn’t fix it. Here’s the updated config

Occupancy Simulator:
  class: OccuSim
  module: occusim
  log: '1'
#  notify: '1'
  enable: input_boolean.vacation_mode,on
#  test: '1'
  dump_times: '1'
#  reset_time: 02:00:00

######
### Weekday Morning Routine
######

  step_weekday_morning_on_name: "Weekday Morning On"
  step_weekday_morning_on_start: "06:00:00"
  step_weekday_morning_on_days: mon,tue,wed,thu,fri
  step_weekday_morning_on_on_1: scene.morning

  step_weekday_morning_off_name: "Weekday Morning Off"
  step_weekday_morning_off_start: "sunrise + 00:45:00"
  step_weekday_morning_off_days: mon,tue,wed,thu,fri
  step_weekday_morning_off_end: "sunrise + 01:00:00"
  step_weekday_morning_off_on_1: scene.house_off

######
### Weekend Morning Routine
######

  step_weekend_morning_on_name: "Weekend Morning On"
  step_weekend_morning_on_start: "06:45:00"
  step_weekend_morning_on_days: sat,sun
  step_weekend_morning_on_end: "07:45:00"
  step_weekend_morning_on_on_1: scene.morning

  step_weekend_morning_off_name: "Weekend Morning Off"
  step_weekend_morning_off_start: "sunrise + 01:05:00"
  step_weekend_morning_off_days: sat,sun
  step_weekend_morning_off_end: "sunrise + 01:25:00"
  step_weekend_morning_off_on_1: scene.house_off

######
### Evening Routine
######

  step_evening_on_name: "Evening First Floor On"
  step_evening_on_start: "sunset + 00:05:00"
  step_evening_on_end: "sunset + 01:00:00"
  step_evening_on_on_1: scene.morning

  step_evening_upstairs_on_name: "Evening Upstairs On"
  step_evening_upstairs_on_relative: "Evening First Floor On"
  step_evening_upstairs_on_start_offset: "00:30:00"
  step_evening_upstairs_on_end_offset: "00:55:00"
  step_evening_upstairs_on_on_1: "scene.upstairs_on"

  step_evening_basement_on_name: "Evening Basement On"
  step_evening_basement_on_relative: "Evening First Floor On"
  step_evening_basement_on_start_offset: "00:30:00"
  step_evening_basement_on_end_offset: "00:55:00"
  step_evening_basement_on_on_1: "scene.basement_on"

  random_first_floor_name: "Random First Floor"
  random_first_floor_start: "Evening First Floor On"
  random_first_floor_end: "Bedtime"
  random_first_floor_minduration: "00:45:00"
  random_first_floor_maxduration: "01:15:00"
  random_first_floor_number: "5"
  random_first_floor_on_1: switch.kitchen_switch
  random_first_floor_off_1: switch.kitchen_switch
  random_first_floor_on_2: light.family_room
  random_first_floor_off_2: light.family_room
  random_first_floor_on_3: light.entry_level
  random_first_floor_off_3: light.entry_level

  random_basement_name: "Random Basement"
  random_basement_start: "Evening Basement On"
  random_basement_end: "Bedtime"
  random_basement_minduration: "00:45:00"
  random_basement_maxduration: "01:15:00"
  random_basement_number: "5"
  random_basement_on_1: light.basement
  random_basement_off_1: light.basement
  random_basement_on_2: light.basement_staircase_level
  random_basement_off_2: light.basement_staircase_level

  random_upstairs_name: "Random Upstairs"
  random_upstairs_start: "Evening Upstairs On"
  random_upstairs_end: "Bedtime"
  random_upstairs_minduration: "00:45:00"
  random_upstairs_maxduration: "01:15:00"
  random_upstairs_number: "5"
  random_upstairs_on_1: light.master_bedroom
  random_upstairs_off_1: light.master_bedroom
  random_upstairs_on_2: light.upstairs_staircase_level
  random_upstairs_off_2: light.upstairs_staircase_level
  random_upstairs_on_3: light.nursery
  random_upstairs_off_3: light.nursery

######
### Bedtime
######

  step_bedtime_name: "Bedtime"
  step_bedtime_start: "21:00:00"
  step_bedtime_end: "22:15:00"
  step_bedtime_on_1: "scene.house_off"

Same problem here:


2018-12-12 19:40:36.416387 WARNING AppDaemon: Traceback (most recent call last):
File “/usr/lib/python3.6/site-packages/appdaemon/appdaemon.py”, line 1581, 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()

how does your config look?

Just looking at the code quickly and it looks like it would be related to start and end times in your config. TSpan is created from a start and end time. If they are the same time, you end up with 0 seconds which would throw that error.

1 Like

nah I just had to quote the minduration and maxduration time strings. I just cut and pasted this stuff from the docs in github so this maybe should be updated.

Ah yes, those time stamps without quotes would be interpreted as integers because foo: 00:01:02 would be interpreted as separate kwargs: foo: 00 and 00:01 and 01:02.

Did you end up getting this to work? Quoting minduration and maxduration hasn’t helped me. I’ve ensured all time strings are quoted, but still the same randrange error as elsewhere in this thread.

Oh wow… I’m not sure where I left this off. I’m not using occusim though.