Occupancy simulator installation

I am running HomeAssistant with Hass.io on a Raspberry Pi3. I have installed AppDaemon as an add-on, but I am not sure I understand how to install OccuSim (https://github.com/acockburn/occusim).
I don’t know how (and from which directory) to run the installation command ($ git clone https://github.com/acockburn/occusim.git).
For now I have manually copied the occusim.py file to the /hadaemon/apps/ directory. Does that work as well?

Don’t know if it is related, but regularly see this error message:
2017-10-15 07:56:21.200126 WARNING Traceback (most recent call last):
File “/usr/lib/python3.6/site-packages/appdaemon/appdaemon.py”, line 845, in check_config
name, new_config[name][“class”],
KeyError: ‘class’

you can use the app by just copiing it like you did.
but you need to read how to work with apps.

in your configuration you need to put the needed args:
like this:

appname:
  module: the_name_op_the_pyscript
  class: the class_in_the_py_script
  any_arg: arg_used_in_the_app
  more_args: Other_args

in the app you find the args and you miss the class setting.

1 Like

OK, it seems I have the installation correct, but I am completely stumped by OccuSim. After installation and initial configuration I got some random automation to work. Great. But, … I can’t seem to change the configuration anymore. Whatever changes I make to the appdaemon.yaml file, my occusim steps remain the same as per the original configuration. Did Occusim make a copy somewhere that I need to change/delete?

These are the steps that get generated at the start of the day:

2017-10-18 03:00:00.083514 INFO Occupancy Simulator: Evening: @ 2017-10-18 19:28:09
2017-10-18 03:00:00.101948 INFO Occupancy Simulator: Evening 2A_on_2: @ 2017-10-18 19:42:21
2017-10-18 03:00:00.112639 INFO Occupancy Simulator: Evening 2A_on_0: @ 2017-10-18 19:43:26
2017-10-18 03:00:00.121312 INFO Occupancy Simulator: Evening 2A_on_1: @ 2017-10-18 19:44:36
2017-10-18 03:00:00.129212 INFO Occupancy Simulator: Evening 2A_off_2: @ 2017-10-18 19:54:07
2017-10-18 03:00:00.136215 INFO Occupancy Simulator: Evening 2A_off_0: @ 2017-10-18 19:57:23
2017-10-18 03:00:00.147930 INFO Occupancy Simulator: Evening 2A_off_1: @ 2017-10-18 20:05:14
2017-10-18 03:00:00.165809 INFO Occupancy Simulator: Night: @ 2017-10-18 21:46:58

and this is my configuration:

AppDaemon:
  cert_verify: False
#  disable_apps: 1
  logfile: STDOUT
  errorfile: STDERR
  threads: 10
  app_dir: /config/hadaemon/apps
HASS:
  ha_url: http://192.168.xx.xx:8123
#  ha_key: password
HADashboard:
#  dash_url: http://cp.local.io
  dash_url: http://192.168.xx.xx:3030
  dash_dir: /config/hadaemon/dashboards
  dash_force_compile: 1

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

  step_evening_name: Evening
  step_evening_start: sunset + 00:45:00

  step_bedtime_name: Bedtime
  step_bedtime_start: 22:20:00
#  step_bedtime_end: 23:00:00
#  step_bedtime_on_1: event.MODE_CHANGE,mode

  random_eveningA_name: EveningA
  random_eveningA_start: Evening
  random_eveningA_end: Bedtime
  random_eveningA_minduration: 00:10:00
  random_eveningA_maxduration: 00:30:00
  random_eveningA_number: 1
  random_eveningA_on_1: scene.A_Night
  random_eveningA_off_1: scene.A_Night_off

You can see that the stepnames that got generated last night have different names than the steps in my appdaemon.yaml file???
I have also tried to separate the Occusim configuration to a separate apps.yaml file (in the same directory as the appdaemon.yaml file), but that doesn’t seem to work either. What am I missing here?

what version from appdaemon are you running?

in the last few versions you need to have 2 files for the configuration.

in that case you need apps.yaml for your occusim settings and there must be no part of that in appdaemon.yaml.
please set logfile and errorfile to a filename (including directory) on a place where appdaemon has writing access.
that way you can see what errors and actions are made from the moment of starting up appdaemon.

i think the names that were running are in your apps.yaml or they are from something you have created before.
after you have the settings right please restart appdaemon to make sure nothing is running from previous settings.

In Hass.io I have installed Appdaemon as an Add-on. It reports as version 0.0.13.
After restarting Appdaemon just now I noticed this in the logs section at the bottom of the Add-on page in HA: 'starting version 3.2.2"
And in the new log file that I now created it says: ‘AppDaemon Version 2.0.8 starting’

As you suggested I have now made the 2 files appdaemon,yaml and apps.yaml. The good news so far is that my error file is empty! Back to testing the random automation’s. Thanks.

hassio uses an old version from appdaemon which (if i remember correct) doesnt have the apps.yaml
it has also problems with input_sliders. (breaking change from HA)
but you dont use input sliders in occupancy, so thats no problem.

i really have no idea if and how and how dependable you can restart AD in hassio, and if it reacts to changes correctly.

hassio is a bad platform for use with programs like appdaemon in my eyes.

You’re right, hass.io uses an AppDaemon version that only needs the appdaemon.yaml file and not the apps.yaml file.
In the AppDaemon Add-On screen in Hass.io there is a ‘button’ to restart AppDaemon, which works very well.
I have learned now that after making changes to the appdaemon.yaml file I need to restart AppDaemon for the changes to take effect.
Your suggestion to include an error file was very useful, thanks. I prefer to see the log entries in the AppDaemon log section in HomeAssistant, so I kept STDOUT for the logfile.
Just to share with the community what is working for me, here is my appdaemon.yaml file:

AppDaemon:
  cert_verify: False
#  disable_apps: 1
  logfile: STDOUT
  errorfile: ./config/hadaemon/error.txt
  threads: 10
  app_dir: /config/hadaemon/apps
HASS:
  ha_url: http://192.168.xx.xx:8123
#  ha_key: password
HADashboard:
  dash_url: http://192.168.xx.xx
  dash_dir: /config/hadaemon/dashboards
  dash_force_compile: 1

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

  step_evening_name: Evening
  step_evening_start: sunset + 00:45:00

  step_bedtime_name: Bedtime
  step_bedtime_start: '22:20:00'

  random_eveningA_name: EveningA
  random_eveningA_start: Evening
  random_eveningA_end: Bedtime
  random_eveningA_minduration: '00:10:00'
  random_eveningA_maxduration: '00:30:00'
  random_eveningA_number: 1
  random_eveningA_on_1: scene.A_Night
  random_eveningA_off_1: scene.A_Night_off

I don’t know if hass.io is a bad platform for apps, for me this app is working fine and everything else that I am doing on hass.io is working very well. My experience so far is that hass.io is an excellent platform for HomeAssistant.

2 Likes

its probably my experience with the load off people unable to solve problems and situations where i cant be off any help.

you are running an old version from AD with the latest version from HA, that means you will run into problems if you want to use input_sliders in a dashboard.

but there is another version from AD addon that runs the latest version from AD. so that could be worth checking out.

i am a heavy user from AD (my apps.yaml is over 1000 lines) and trouble like that what hassio give would make me insane :wink:

i am happy that there are people who are happy to use it.

@ReneTode

I wish to start random on/off lights when my system alarm change in away mode.
I’m unable to works it… what’s wrong?

my apps.yam file have this entry…

Occupancy Simulator:
  class: OccuSim
  module: occusim
  log: 1
  notify: 1
  enable: input_boolean.systemalarm_away,on
  dump_times: 1

  step_starttime_name: Start_time
  step_starttime_start: '15:30:00'

  step_stoptime_name: Stop_time
  step_stoptime_start: '00:00:00'

  random_lightsaway_name: Lights_away
  random_lightsaway_start: Start_time
  random_lightsaway_end: Stop_time
  random_lightsaway_minduration: '00:00:05'
  random_lightsaway_maxduration: '00:00:20'
  random_lightsaway_number: 100
  random_lightsaway_on_1: switch.sonoff_sogg
  random_lightsaway_off_1: switch.sonoff_sogg

1 issue i can see.

stop time is before start time.
a day runs from 00:00:00 to 23:59:59
and occusim can only work inside 1 day.

if there are other issues i cant say without errors.

I corrected stop_time to '23:59:59" but unsuccesfull… it do not works and do not give me errors in log file

did you have logfiles set in appdaemon.yaml?
is there anything in your logfiles?
is appdaemon running?
did you try restarting appdaemon?

In appdaemon.yaml I have:

log:
  logfile: STDOUT
  errorfile: STDERR
appdaemon:
  logfile: /home/homeassistant/.homeassistant/config/logs/appdaemon.log
  errorfile: /home/homeassistant/.homeassistant/config/logs/appdaemonerr.log
  logsize: 100000
  log_generations: 3
  threads: 10
  app_dir: /config/appdaemon/apps

no error files have been generated

Appdaemon is running becouse I’ve system alarm by Runningman84 and it is working fine

I’ve Appdaemon 3 v. 1.2 and today I restarted My Hassio many many times

you got appdaemon 3 style settings

log:
  logfile: STDOUT
  errorfile: STDERR

and appdaemon 2 style settings

appdaemon:
  logfile: /home/homeassistant/.homeassistant/config/logs/appdaemon.log
  errorfile: /home/homeassistant/.homeassistant/config/logs/appdaemonerr.log

in your appdaemon.yaml

if you are running appdaemon V3 then those lines:

  logfile: /home/homeassistant/.homeassistant/config/logs/appdaemon.log
  errorfile: /home/homeassistant/.homeassistant/config/logs/appdaemonerr.log

are useless.

you talk about hassio, and those lines suggest hasbian.

you should at least have logs showing that appdaemon is started and that shows which apps are started etc.
if you dont know how to find those logs (because they are set to STDOUT and STDERR) then you need to set you logfiles to a place where the user that starts appdaemon has full (read/write/execute) access.

the only way to know if appdaemon is running, if apps are working or not and if something is wrong is by looking at the logfiles.

I stopped uninstalled and reinstalled Appdaemon and now it seem works fine :slight_smile:
Many thanks ReneTode!!!

change your settings. or you also wont find the next problem.
find out how and where your logs go, because its the basics from your automations.

if you uninstalled and reinstalled and now its working then i am sure appdaemon wasnt running and that was your problem.
and absolutly the only way to see if appdaemon is running as it should is by looking at the logs.

@ReneTode
I have this error in Hassio log:

18-10-28 20:18:54 WARNING (MainThread) [hassio.api.security] /addons/a0d7b954_appdaemon3/info no role for a0d7b954_appdaemon3
18-10-28 20:18:54 ERROR (MainThread) [hassio.api.security] Invalid token for access /addons/a0d7b954_appdaemon3/info

This is the log of Appdaemon

parse error: Expected string key before ':' at line 1, column 4
ERROR: Unknown HTTP error occured
 
parse error: Expected string key before ':' at line 1, column 4
ERROR: Unknown HTTP error occured
 From: 
parse error: Expected string key before ':' at line 1, column 4
ERROR: Unknown HTTP error occured
 By: 
-----------------------------------------------------------
[cont-init.d] 00-banner.sh: exited 0.
[cont-init.d] 01-log-level.sh: executing... 
Log level is set to INFO
[cont-init.d] 01-log-level.sh: exited 0.
[cont-init.d] 02-updates.sh: executing... 
parse error: Expected string key before ':' at line 1, column 4
ERROR: Unknown HTTP error occured
parse error: Expected string key before ':' at line 1, column 4
ERROR: Unknown HTTP error occured
INFO: You are running the latest version of this add-on
[cont-init.d] 02-updates.sh: exited 0.
[cont-init.d] 20-init-configuration.sh: executing... 
[cont-init.d] 20-init-configuration.sh: exited 0.
[cont-init.d] 21-compiled-dir.sh: executing... 
[cont-init.d] 21-compiled-dir.sh: exited 0.
[cont-init.d] 30-auto-password.sh: executing... 
[cont-init.d] 30-auto-password.sh: exited 0.
[cont-init.d] 31-ha-url.sh: executing... 
WARNING: You are using an non-recommended Home Assistant URL!
WARNING: Setting the "ha_url" option in your AppDaemon config to
WARNING: "http://hassio/homeassistant" is recommended!
[cont-init.d] 31-ha-url.sh: exited 0.
[cont-init.d] 50-compiled-symlink.sh: executing... 
[cont-init.d] 50-compiled-symlink.sh: exited 0.
[cont-init.d] 80-system-packages.sh: executing... 
[cont-init.d] 80-system-packages.sh: exited 0.
[cont-init.d] 81-python-packages.sh: executing... 
[cont-init.d] 81-python-packages.sh: exited 0.
[cont-init.d] done.
[services.d] starting services
[services.d] done.
2018-10-29 00:13:20.605076 INFO AppDaemon Version 3.0.1 starting
2018-10-29 00:13:20.605763 INFO Configuration read from: /config/appdaemon/appdaemon.yaml
2018-10-29 00:13:20.609407 INFO AppDaemon: Starting Apps
2018-10-29 00:13:20.618352 INFO AppDaemon: Loading Plugin HASS using class HassPlugin from module hassplugin
2018-10-29 00:13:20.711852 INFO AppDaemon: HASS: HASS Plugin Initializing
2018-10-29 00:13:20.712875 INFO AppDaemon: HASS: HASS Plugin initialization complete
2018-10-29 00:13:20.713846 INFO Starting Dashboards
2018-10-29 00:13:20.760709 INFO API is disabled
2018-10-29 00:13:21.460699 INFO AppDaemon: HASS: Connected to Home Assistant 0.80.3
2018-10-29 00:13:21.964256 INFO AppDaemon: Got initial state from namespace default
2018-10-29 00:13:24.088650 INFO AppDaemon: Reading config
2018-10-29 00:13:24.246505 INFO AppDaemon: /config/appdaemon/apps/apps.yaml added or modified
2018-10-29 00:13:24.247076 INFO AppDaemon: /config/appdaemon/apps/apps.yaml added or modified
2018-10-29 00:13:24.247979 INFO AppDaemon: App 'alarm_system' added
2018-10-29 00:13:24.248858 INFO AppDaemon: App 'Occupancy Simulator' added
2018-10-29 00:13:24.250263 INFO AppDaemon: Adding /config/appdaemon/apps to module import path
2018-10-29 00:13:24.252700 INFO AppDaemon: Loading App Module: /config/appdaemon/apps/alarm.py
2018-10-29 00:13:24.354292 INFO AppDaemon: Loading App Module: /config/appdaemon/apps/occusim.py
2018-10-29 00:13:24.373837 INFO AppDaemon: Initializing app alarm_system using class AlarmSystem from module alarm
2018-10-29 00:13:25.053385 INFO alarm_system: Hello from AlarmSystem
2018-10-29 00:13:25.058550 INFO alarm_system: Got armed_home sensors ['binary_sensor.door_window_sensor_158d0001a3dea5', 'binary_sensor.door_window_sensor_158d0001a3e062', 'binary_sensor.door_window_sensor_158d0001b14427', 'binary_sensor.door_window_sensor_158d0001e453c0', 'binary_sensor.door_window_sensor_158d0001e45446', 'binary_sensor.door_window_sensor_158d0001657248', 'binary_sensor.door_window_sensor_158d0001de8821', 'binary_sensor.door_window_sensor_158d0001de92ce', 'binary_sensor.door_window_sensor_158d0001de76a8', 'binary_sensor.door_window_sensor_158d0001e45b81']
2018-10-29 00:13:25.064097 INFO alarm_system: Got armed_away sensors ['binary_sensor.door_window_sensor_158d0001a3dea5', 'binary_sensor.door_window_sensor_158d0001a3e062', 'binary_sensor.door_window_sensor_158d0001b14427', 'binary_sensor.door_window_sensor_158d0001e453c0', 'binary_sensor.door_window_sensor_158d0001e45446', 'binary_sensor.door_window_sensor_158d0001657248', 'binary_sensor.door_window_sensor_158d0001de8821', 'binary_sensor.door_window_sensor_158d0001de92ce', 'binary_sensor.door_window_sensor_158d0001de76a8', 'binary_sensor.door_window_sensor_158d0001e45b81', 'binary_sensor.motion_sensor_158d00016dad06', 'binary_sensor.motion_sensor_158d00016dafd8', 'binary_sensor.motion_sensor_158d0001a25221', 'binary_sensor.motion_sensor_158d0001a33a44', 'binary_sensor.motion_sensor_158d0002234653', 'binary_sensor.motion_sensor_158d0002236904', 'binary_sensor.motion_sensor_158d0001e5414c', 'binary_sensor.motion_sensor_158d0002234653', 'binary_sensor.motion_sensor_158d0002236904']
2018-10-29 00:13:25.069549 INFO alarm_system: Got device trackers ['device_tracker.samsung_s9_wifi', 'device_tracker.samsung_s9_bt', 'device_tracker.samsung_s9_ping', 'device_tracker.huawei_p8_wifi', 'device_tracker.huawei_p8_bt', 'device_tracker.huawei_p8_ping', 'device_tracker.xiaomi_redmi_wifi', 'device_tracker.xiaomi_redmi_bt']
2018-10-29 00:13:25.077597 INFO alarm_system: Got 3 device_trackers home and 3 device_trackers not home
2018-10-29 00:13:25.083337 INFO alarm_system: Got guest_mode False
2018-10-29 00:13:25.088583 INFO alarm_system: Got vacation_mode False
2018-10-29 00:13:25.093869 INFO alarm_system: Got silent mode False
2018-10-29 00:13:25.098812 INFO alarm_system: Got info volume 10
2018-10-29 00:13:25.103848 INFO alarm_system: Got alarm volume 99
2018-10-29 00:13:25.108815 INFO alarm_system: Got notify service notify.hassio
2018-10-29 00:13:25.114088 INFO alarm_system: Got alarm state disarmed
2018-10-29 00:13:25.117117 WARNING AppDaemon: alarm_system: Entity device_tracker.samsung_s9_ping not found in AppDaemon
2018-10-29 00:13:25.118122 WARNING AppDaemon: alarm_system: Entity device_tracker.samsung_s9_ping not found in AppDaemon
2018-10-29 00:13:25.119755 WARNING AppDaemon: alarm_system: Entity device_tracker.huawei_p8_ping not found in AppDaemon
2018-10-29 00:13:25.121117 WARNING AppDaemon: alarm_system: Entity device_tracker.huawei_p8_ping not found in AppDaemon
2018-10-29 00:13:26.166765 INFO AppDaemon: Initializing app Occupancy Simulator using class OccuSim from module occusim
2018-10-29 00:13:26.186288 WARNING AppDaemon: ------------------------------------------------------------
2018-10-29 00:13:26.192597 WARNING AppDaemon: Unexpected error running initialize() for Occupancy Simulator
2018-10-29 00:13:26.194956 WARNING AppDaemon: ------------------------------------------------------------
2018-10-29 00:13:26.217272 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 65, in create_events
    start = self.parse_time(start_p)
  File "/usr/lib/python3.6/site-packages/appdaemon/appapi.py", line 277, in parse_time
    return self.AD.parse_time(time_str, name)
  File "/usr/lib/python3.6/site-packages/appdaemon/appdaemon.py", line 1067, in parse_time
    parts = re.search('^(\d+):(\d+):(\d+)', time_str)
  File "/usr/lib/python3.6/re.py", line 182, in search
    return _compile(pattern, flags).search(string)
TypeError: expected string or bytes-like object
2018-10-29 00:13:26.218407 WARNING AppDaemon: ------------------------------------------------------------
2018-10-29 00:13:26.223682 INFO AppDaemon: App initialization complete

the error and warning are 11 days old and you reinstalled so you can ignore that.

in your alarmsystem app you got 2 devicetrackers that are not in home assistant at the moment you started appdaemon.
and the occupance app expects times to be presented as strings and it seems that thats not the case.
you when changing you probably forgot some quotes somewhere.

I upgraded to Appdaemon 1.5.0 but Occusim do not works…

what’s this error?

2018-10-29 08:31:55.861842 WARNING AppDaemon: ------------------------------------------------------------
2018-10-29 08:31:55.862729 WARNING AppDaemon: Unexpected error running initialize() for Occupancy Simulator
2018-10-29 08:31:55.865297 WARNING AppDaemon: ------------------------------------------------------------
2018-10-29 08:31:55.877153 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 65, in create_events
    start = self.parse_time(start_p)
  File "/usr/lib/python3.6/site-packages/appdaemon/appapi.py", line 277, in parse_time
    return self.AD.parse_time(time_str, name)
  File "/usr/lib/python3.6/site-packages/appdaemon/appdaemon.py", line 1067, in parse_time
    parts = re.search('^(\d+):(\d+):(\d+)', time_str)
  File "/usr/lib/python3.6/re.py", line 182, in search
    return _compile(pattern, flags).search(string)
TypeError: expected string or bytes-like object

I’ve this error in Appdaemon log:

2018-10-29 22:39:14.256249 INFO AppDaemon: Initializing app Occupancy Simulator using class OccuSim from module occusim
    2018-10-29 22:39:14.273060 WARNING AppDaemon: ------------------------------------------------------------
    2018-10-29 22:39:14.274029 WARNING AppDaemon: Unexpected error running initialize() for Occupancy Simulator
    2018-10-29 22:39:14.274924 WARNING AppDaemon: ------------------------------------------------------------
    2018-10-29 22:39:14.283505 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 65, in create_events
        start = self.parse_time(start_p)
      File "/usr/lib/python3.6/site-packages/appdaemon/appapi.py", line 277, in parse_time
        return self.AD.parse_time(time_str, name)
      File "/usr/lib/python3.6/site-packages/appdaemon/appdaemon.py", line 1067, in parse_time
        parts = re.search('^(\d+):(\d+):(\d+)', time_str)
      File "/usr/lib/python3.6/re.py", line 182, in search
        return _compile(pattern, flags).search(string)
    TypeError: expected string or bytes-like object