Occupancy simulator help newbie

hi,
i new to home assistant and would really appericate some help

i’ve installed HA and appdaemon (hello world worked as expected) i would really like to use occu sim to randomly tuen on and off my light and tv when im away.

here is my appdaemon yaml file

AppDaemon:
  logfile: STDOUT
  errorfile: STDERR
  logsize: 100000
  log_generations: 3
  threads: 10
  cert_path: 
  cert_verify: True
  timezone: = <timezone>
  api_port: 5000
  api_key: 
  api_ssl_certificate: 
  api_ssl_key: 
HASS:
  ha_url: http://192.168.0.13:8123
  ha_key: password123

here is my app.yaml file

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

  random_holiday_name: Evening holiday
  random_holiday_start: Evening
  random_holiday_end: Night
  random_holiday_maxduration: 00:30:00
  random_holiday_minduration: 00:03:00
  random_holiday_number: '3'
  random_holiday_off_1: scene.holiday_off
  random_holiday_on_1: scene.holiday_on

when i run appdaemon i get the following error

2017-10-23 11:38:07.728796 INFO AppDaemon Version 2.1.10 starting
2017-10-23 11:38:07.729841 INFO Configuration read from: /home/homeassistant/.homeassistant/conf/appdaemon.yaml
2017-10-23 12:38:07.837332 INFO Starting Apps
2017-10-23 12:38:07.927453 INFO Got initial state
2017-10-23 12:38:07.928936 INFO Loading Module: /home/homeassistant/.homeassistant/conf/apps/occusim.py
2017-10-23 12:38:07.930795 INFO Loading Object Occupancy Simulator using class OccuSim from module occusim
2017-10-23 12:38:07.934714 WARNING ------------------------------------------------------------
2017-10-23 12:38:07.935119 WARNING Unexpected error during loading of Occupancy Simulator:
2017-10-23 12:38:07.935417 WARNING ------------------------------------------------------------
2017-10-23 12:38:07.938251 WARNING Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/appdaemon/appdaemon.py", line 911, in read_app
    init_object(name, class_name, module_name, conf.app_config[name])
  File "/usr/local/lib/python3.4/dist-packages/appdaemon/appdaemon.py", line 582, in init_object
    conf.objects[name]["object"].initialize()
  File "/home/homeassistant/.homeassistant/conf/apps/occusim.py", line 31, in initialize
    self.create_events({})
  File "/home/homeassistant/.homeassistant/conf/apps/occusim.py", line 157, in create_events
    starttime = events[startstep]["event"]
KeyError: 'Evening'

2017-10-23 12:38:07.938704 WARNING ------------------------------------------------------------

what am i doing wrong?

You can;t have a random event without 2 scheduled events to use as start and end times.

1 Like

Sorry to be a pest
And Thank You for the response
How would that look? Would I use the same scene?

There’s an explanation here:

Basically you need to create scheduled events for Evening and Night.

Oh okay
So if I’m understanding this correctly im giving it a parameter to work within.

Start after a certain time “evening” and an end “night”

and use times like this

‘00:30:00’ or this “00:30:00”

but not like this

00:30:00

unless its part of a string

1 Like

Yep correct :slight_smile:

1 Like

Hi, guys
I really appericate all the help

so I now have the following in my app file

Occupancy Simulator:
  module: occusim
  class: OccuSim
  log: 1
  #notify: 1
  enable: input_boolean.holiday,off
  test: 1
  dump_times: 1
  #reset_time: 02:00:00
  
  random_holiday_end: Night
  random_holiday_maxduration: 00:30:00
  random_holiday_minduration: 00:03:00
  random_holiday_name: Evening holiday
  random_holiday_number: '3'
  random_holiday_off_1: scene.holiday_off
  random_holiday_on_1: scene.holiday_on
  random_holiday_start: Evening

  step_evening_name: Evening
  step_evening_start: sunset - 00:45:00

  step_night_end: '22:30:00'
  step_night_name: Night
  step_night_on_1: event.MODE_CHANGE,mode
  step_night_start: '21:30:00'

and when I ran the appdeamon I see this

2017-10-24 09:13:52.181856 INFO AppDaemon Version 2.1.10 starting
2017-10-24 09:13:52.182377 INFO Configuration read from: /home/homeassistant/.homeassistant/conf/appdaemon.yaml
2017-10-24 10:13:52.288375 INFO Starting Apps
2017-10-24 10:13:52.387548 INFO Got initial state
2017-10-24 10:13:52.389016 INFO Loading Module: /home/homeassistant/.homeassistant/conf/apps/occusim.py
2017-10-24 10:13:52.390813 INFO Loading Object Occupancy Simulator using class OccuSim from module occusim
2017-10-24 10:13:52.565250 INFO Occupancy Simulator: Evening: @ 2017-10-24 17:06:10
2017-10-24 10:13:52.568618 INFO Occupancy Simulator: Evening holiday_on_1: @ 2017-10-24 18:17:56
2017-10-24 10:13:52.571903 INFO Occupancy Simulator: Evening holiday_off_1: @ 2017-10-24 18:42:19
2017-10-24 10:13:52.575291 INFO Occupancy Simulator: Evening holiday_on_0: @ 2017-10-24 19:06:44
2017-10-24 10:13:52.578589 INFO Occupancy Simulator: Evening holiday_off_0: @ 2017-10-24 19:22:57
2017-10-24 10:13:52.581850 INFO Occupancy Simulator: Evening holiday_on_2: @ 2017-10-24 21:35:29
2017-10-24 10:13:52.585169 INFO Occupancy Simulator: Evening holiday_off_2: @ 2017-10-24 21:36:10
2017-10-24 10:13:52.588451 INFO Occupancy Simulator: Night: @ 2017-10-24 21:48:40
2017-10-24 10:13:52.588851 INFO Loading Module: /home/homeassistant/.homeassistant/conf/apps/hello.py
2017-10-24 10:13:52.590219 INFO App initialization complete
2017-10-24 10:13:52.590909 INFO Dashboards are disabled
2017-10-24 10:13:52.591226 INFO Starting API
2017-10-24 10:13:52.604572 INFO Connected to Home Assistant 0.55.1

can you please confirm. Will it continue to generate randoms time each day, yet only trigger them if I switch my boolean switch to on?

like i said times should be strings. i could be that you get unexpected results when you dont use it like:

random_holiday_maxduration: ‘00:30:00’

1 Like

I copied over the settings from the occusim example on github.

the occupancy app was written for the older version from appdaemon which still had .cfg configuration and where it wasnt yaml.
yaml does thing different when it isnt between quotes.
so for this app it is good practice to use all times in quotes, to make sure they are handled well.

1 Like

Oh okay
Thank you for the help

Could you help me with how to trigger this?

Will it continue to generate randoms time each day, yet only trigger them if I switch my boolean switch to on?

thats right.

1 Like

Great
One last question
How do I get occusim to auto start after a reboot?

if appdaemon starts, occusim is automaticly started.

how to start appdaemon automaticly is in the docs. (if you havent done that already.)

hi ReneTode,

i now have occusim working. thank you so much for the help this far. i really do appericate it.

i’ve looked at the documents to have appdaemon auto start on reboot but im struggling

i installed HA by the All in One install

so i created the following required file

appdaemon.service (located in /etc/systemd/system)

[Unit]
Description=AppDaemon
After=home-assistant.service
[Service]
Type=simple
User=homeassistant
ExecStart=/usr/local/bin/appdaemon -c /home/homeassistant/.homeassistant/conf
[Install]
WantedBy=multi-user.target

i changed
After=home-assistant.service
User=homeassistant
ExecStart=/usr/local/bin/appdaemon -c /home/homeassistant/.homeassistant/conf
to match my set up

i then ran
sudo systemctl daemon-reload
which was fine

then i ran
sudo systemctl enable appdaemon.service --now

which returns
systemctl: unrecognized option '--now'

how do i resolve this?

i am sorry but with that i cant help.
my startup is completely different and with that kind of setup i have never worked.

i hope someone else can help you with that.
but there is a lot of information about how to configure and start systemctl on the forum and you could also google for
sudo systemctl enable

if amyone could help

i‘ve followed all the steps

pi@raspberrypi:~ $ sudo vi /etc/systemd/system/[email protected]
pi@raspberrypi:~ $ sudo systemctl enable [email protected]
pi@raspberrypi:~ $ sudo systemctl start appdaemon@appdaemon

and when i check the status i get the following error

pi@raspberrypi:~ $ sudo systemctl status appdaemon@appdaemon
● [email protected] - AppDaemon
   Loaded: loaded (/etc/systemd/system/[email protected]; enabled)
   Active: failed (Result: exit-code) since Tue 2017-10-24 21:42:55 UTC; 46s ago
  Process: 3576 ExecStart=/usr/local/bin/appdaemon -c /home/homeassistant/.homea                                                                                                                                                             ssistant/conf (code=exited, status=1/FAILURE)
 Main PID: 3576 (code=exited, status=1/FAILURE)

Oct 24 21:42:55 raspberrypi appdaemon[3576]: BaseRotatingHandler.__init__(se...)
Oct 24 21:42:55 raspberrypi appdaemon[3576]: File "/usr/lib/python3.4/loggin..._
Oct 24 21:42:55 raspberrypi appdaemon[3576]: logging.FileHandler.__init__(se...)
Oct 24 21:42:55 raspberrypi appdaemon[3576]: File "/usr/lib/python3.4/loggin..._
Oct 24 21:42:55 raspberrypi appdaemon[3576]: StreamHandler.__init__(self, se...)
Oct 24 21:42:55 raspberrypi appdaemon[3576]: File "/usr/lib/python3.4/loggin...n
Oct 24 21:42:55 raspberrypi appdaemon[3576]: return open(self.baseFilename, ...)
Oct 24 21:42:55 raspberrypi appdaemon[3576]: PermissionError: [Errno 13] Per...'
Oct 24 21:42:55 raspberrypi systemd[1]: [email protected]: main pr...E
Oct 24 21:42:55 raspberrypi systemd[1]: Unit [email protected] ent....
Hint: Some lines were ellipsized, use -l to show in full.

seems like the filerights are not right to be accessed by the service.

Hi
I removed
User=homeassistant
And it’s now working

Cheers

1 Like