appdaemon icon indicating copy to clipboard operation
appdaemon copied to clipboard

Evaluating startup conditions not working as expected

Open electrofloat opened this issue 5 years ago • 18 comments

Something is weird about the startup conditions. If I have this in appdaemon.yaml:

      appdaemon_startup_conditions:
        - state: {entity: "zwave.z_wave_sigma_designs_uzb_z_wave_usb_adapter", value: {state: "ready"}}
        - state: {entity: "zwave.eurotronic_eur_spiritz_wall_radiator_thermostat_2", value: {state: "ready"}}
        - state: {entity: "zwave.aeon_labs_zw100_multisensor_6", value: {state: "ready"}}

I get this in the log:

2020-10-05 18:07:32.843431 INFO HASS: Evaluating startup conditions
2020-10-05 18:07:32.843624 WARNING HASS: Disconnected from Home Assistant, retrying in 5 seconds
2020-10-05 18:07:37.864619 INFO HASS: Connected to Home Assistant 0.115.1
2020-10-05 18:07:37.883431 INFO HASS: Evaluating startup conditions
2020-10-05 18:07:37.886202 INFO HASS: Startup condition met: hass state=RUNNING
2020-10-05 18:07:37.886407 INFO HASS: All startup conditions met

If I have this in appdaemon.yaml:

      appdaemon_startup_conditions:
        - state: {entity: "zwave.z_wave_sigma_designs_uzb_z_wave_usb_adapter", value: {state: "ready"}}
        - state: {entity: "zwave.eurotronic_eur_spiritz_wall_radiator_thermostat_2", value: {state: "ready"}}
        - state: {entity: "zwave.aeon_labs_zw100_multisensor_6", value: {state: "ready"}}
      plugin_startup_conditions:
        - state: {entity: "zwave.z_wave_sigma_designs_uzb_z_wave_usb_adapter", value: {state: "ready"}}

I get this in the log: (repeats forever)

2020-10-05 18:09:48.209995 INFO HASS: Evaluating startup conditions
2020-10-05 18:09:48.210211 WARNING HASS: Disconnected from Home Assistant, retrying in 5 seconds
2020-10-05 18:09:53.231405 INFO HASS: Connected to Home Assistant 0.115.1
2020-10-05 18:09:53.251576 INFO HASS: Evaluating startup conditions
2020-10-05 18:09:53.252026 WARNING HASS: Disconnected from Home Assistant, retrying in 5 seconds
2020-10-05 18:09:58.266462 INFO HASS: Connected to Home Assistant 0.115.1
2020-10-05 18:09:58.274273 INFO HASS: Evaluating startup conditions
2020-10-05 18:09:58.274454 WARNING HASS: Disconnected from Home Assistant, retrying in 5 seconds
2020-10-05 18:10:03.297023 INFO HASS: Connected to Home Assistant 0.115.1
2020-10-05 18:10:03.328630 INFO HASS: Evaluating startup conditions

If I have this in appdaemon.yaml:

      appdaemon_startup_conditions:
        state: {entity: "zwave.z_wave_sigma_designs_uzb_z_wave_usb_adapter", value: {state: "ready"}}
        state: {entity: "zwave.eurotronic_eur_spiritz_wall_radiator_thermostat_2", value: {state: "ready"}}
        state: {entity: "zwave.aeon_labs_zw100_multisensor_6", value: {state: "ready"}}
      plugin_startup_conditions:
        state: {entity: "zwave.z_wave_sigma_designs_uzb_z_wave_usb_adapter", value: {state: "ready"}}
        state: {entity: "zwave.eurotronic_eur_spiritz_wall_radiator_thermostat_2", value: {state: "ready"}}
        state: {entity: "zwave.aeon_labs_zw100_multisensor_6", value: {state: "ready"}}

I get this in the log;

2020-10-05 18:11:14.229270 INFO HASS: Evaluating startup conditions
2020-10-05 18:11:14.230885 INFO HASS: Startup condition met: hass state=RUNNING
2020-10-05 18:11:14.235112 INFO HASS: Startup condition met: zwave.aeon_labs_zw100_multisensor_6={'state': 'ready'}
2020-10-05 18:11:14.235285 INFO HASS: All startup conditions met
  • Why is it not logging all the met startup conditions in the first one, when it does this in the last one?
  • Why is it stuck in connected/evaluating/disconnected state in the second one?
  • What am i doing wrong?

electrofloat avatar Oct 05 '20 16:10 electrofloat

i never use conditions and i didnt look at the code, so my answers are limited but, the docs example shows

plugin_startup_conditions: event: {event_type: zwave.network_ready}

which isnt a list, so its possible that the code expects a dict. (so without - ) if that is true there can be only 1 delay, 1 state and 1 event because this:

      appdaemon_startup_conditions:
        state: {entity: "zwave.z_wave_sigma_designs_uzb_z_wave_usb_adapter", value: {state: "ready"}}
        state: {entity: "zwave.eurotronic_eur_spiritz_wall_radiator_thermostat_2", value: {state: "ready"}}
        state: {entity: "zwave.aeon_labs_zw100_multisensor_6", value: {state: "ready"}}

is always wrong, no matter what the code does. when you do it like that then appdaemon_startup_conditions contains a dict with 3 times the same key. which results in that the first 2 just are obsolete. thats how yaml works.

if both a list and 1 single entry are allowed (which the docs dont state) then in the code there is a difference between a list of conditions and 1 single condition. and in that case it makes sense just to show in the log if 1 single condition is met (like your last example) or just state that all conditions are met (like in your first example)

i dont know zwave. but does zwave.z_wave_sigma_designs_uzb_z_wave_usb_adapter first get the value ready, and a different value afterwards? if so then AD starts when it is ready, but when the plugin evaluation comes it is already changed, so at that point the plugin condition is never met. thats the only explenation i can think of for your second example.

so you should use the first or second, but for sure NEVER the last.

ReneTode avatar Oct 05 '20 19:10 ReneTode

The devices were in the 'ready' during these tests and never changed state.

I am also assuming that only 1 delay, 1 state, 1 event is what possible at the moment. It would be nice to have more and have a condition setting to tell whether all of them (and), or any of them (or) have to be in the given state.

electrofloat avatar Oct 05 '20 19:10 electrofloat

ill need to ask @acockburn if it should be possible to check for several states (i suspect so) but then the docs dont tell how and the examples are not good.

so he might want to give some more insight.

ReneTode avatar Oct 05 '20 21:10 ReneTode

One delay and one event is correct, states can be a single entry but you can test for multiple fields within the value attribute ... or so it seems from checking the code on my phone, so I may be a little off.

acockburn avatar Oct 06 '20 00:10 acockburn

I see. Can we convert this issue to a feature request/enhancement then to be able to have multiple delays, events, states, and also have a condition between them (any of, all of)?

electrofloat avatar Oct 07 '20 15:10 electrofloat

I'd like to add my +1 for the disconnect reconnect loop.

My config "works" when I don't put the conditions in:

  plugins:
    HASS:
      type: hass
      ha_url: "http://192.168.178.11:8123"
      token: !secret token
      api_port: 8123
      #plugin_startup_conditions:
      #  delay: 180
      #appdaemon_startup_conditions:
      #  delay: 180
  time_zone: Europe/Berlin
  latitude: 55.152950
  longitude: 11.519330
  elevation: 1
http:
  url: http://raspberrypi:5050
admin:
api:
hadashboard:

But as soon as I comment the commented out conditions in I get this in a loop:

2020-11-22 06:16:07.059888 INFO HASS: Connected to Home Assistant 0.118.2
2020-11-22 06:16:07.102351 INFO HASS: Evaluating startup conditions
2020-11-22 06:16:07.102970 INFO HASS: Delaying startup for 180 seconds
2020-11-22 06:19:07.113749 INFO HASS: Startup condition met: hass state=RUNNING
2020-11-22 06:19:07.114481 INFO HASS: All startup conditions met
2020-11-22 06:19:07.494298 INFO AppDaemon: Processing restart for HASS
2020-11-22 06:19:08.154861 WARNING HASS: Disconnected from Home Assistant, retrying in 5 seconds
2020-11-22 06:19:13.173281 INFO HASS: Connected to Home Assistant 0.118.2
2020-11-22 06:19:13.299036 INFO HASS: Evaluating startup conditions
2020-11-22 06:19:13.300000 INFO HASS: Delaying startup for 180 seconds
2020-11-22 06:22:13.322041 INFO HASS: Startup condition met: hass state=RUNNING
2020-11-22 06:22:13.322841 INFO HASS: All startup conditions met
2020-11-22 06:22:13.678645 INFO AppDaemon: Processing restart for HASS
2020-11-22 06:22:14.382675 WARNING HASS: Disconnected from Home Assistant, retrying in 5 seconds
2020-11-22 06:22:19.393871 INFO HASS: Connected to Home Assistant 0.118.2
2020-11-22 06:22:19.426968 INFO HASS: Evaluating startup conditions
2020-11-22 06:22:19.427661 INFO HASS: Delaying startup for 180 seconds
2020-11-22 06:25:19.439678 INFO HASS: Startup condition met: hass state=RUNNING
2020-11-22 06:25:19.440278 INFO HASS: All startup conditions met
2020-11-22 06:25:19.741461 INFO AppDaemon: Processing restart for HASS
2020-11-22 06:25:20.429198 WARNING HASS: Disconnected from Home Assistant, retrying in 5 seconds
2020-11-22 06:25:25.448491 INFO HASS: Connected to Home Assistant 0.118.2
2020-11-22 06:25:25.493019 INFO HASS: Evaluating startup conditions
2020-11-22 06:25:25.493770 INFO HASS: Delaying startup for 180 seconds
2020-11-22 06:28:25.515859 INFO HASS: Startup condition met: hass state=RUNNING
2020-11-22 06:28:25.516415 INFO HASS: All startup conditions met
2020-11-22 06:28:25.858628 INFO AppDaemon: Processing restart for HASS
2020-11-22 06:28:26.551685 WARNING HASS: Disconnected from Home Assistant, retrying in 5 seconds
2020-11-22 06:28:31.574833 INFO HASS: Connected to Home Assistant 0.118.2
2020-11-22 06:28:31.629928 INFO HASS: Evaluating startup conditions
2020-11-22 06:28:31.630785 INFO HASS: Delaying startup for 180 seconds
2020-11-22 06:31:31.643016 INFO HASS: Startup condition met: hass state=RUNNING
2020-11-22 06:31:31.643572 INFO HASS: All startup conditions met
2020-11-22 06:31:31.935918 INFO AppDaemon: Processing restart for HASS
2020-11-22 06:31:32.661830 WARNING HASS: Disconnected from Home Assistant, retrying in 5 seconds

Ad is 4.0.5.

Am I using these options incorrectly or is this a bug?

I omitted app initialization and cancelation because it made seeing the loop hard. Let me know if ai should paste the full log.

dekiesel avatar Nov 22 '20 07:11 dekiesel

yes it isnt working as it should. my advise:

  1. remove api-port from the plugin section, because it doesnt do anything
  2. just use appdaemon_startup_conditions, and always restart AD when you restart HA.

ReneTode avatar Nov 22 '20 21:11 ReneTode

So there is no chance to fix that problem automatically? i have to restart by hand?

KimHEF avatar May 29 '21 22:05 KimHEF

you always can restart AD automaticly, some period after HA is restarted.

personally i always did restart my complete device when i restarted HA.

ReneTode avatar May 30 '21 19:05 ReneTode

But that is my Problem. When i restart my whole system i have to restart the AD Container Manually after HA started.

KimHEF avatar May 30 '21 20:05 KimHEF

why? you can just create a startup script for your system, or you can use cron or systemmd.

ReneTode avatar May 30 '21 21:05 ReneTode

Dont get me wrong. AD and HA both Container are starting at the Boot but it seems that AD is done before HA and they have no Connection so i have to restart the AD Container manually. I tried a Composefile that say AD depands on HA but that didn't solve the problem.

KimHEF avatar May 31 '21 05:05 KimHEF

if you start both on boot, and AD is started first then you need to delay that startup.

ReneTode avatar May 31 '21 19:05 ReneTode

Is there a recommended simple way with docker? Or how would you do it?

KimHEF avatar May 31 '21 20:05 KimHEF

i really dont know. i have never used docker. maybe that @Odianosen25 knows how to delay the startup from a docker.

i use cron to start my HA and AD instances. but im running in venv.

ReneTode avatar May 31 '21 20:05 ReneTode

Is there a recommended simple way with docker? Or how would you do it?

Try entrypoint: sh -c "sleep 30 && ./dockerStart.sh". It works for me.

definitio avatar May 31 '21 21:05 definitio

Is there a recommended simple way with docker? Or how would you do it?

Try entrypoint: sh -c "sleep 30 && ./dockerStart.sh". It works for me.

Sorry but i am very new into that. Where do I have to enter this?

Could i paste it in the Compose file?

KimHEF avatar May 31 '21 21:05 KimHEF

@KimHEF Yes, this is part of my compose file:

services:
  appdaemon:
    container_name: appdaemon
    image: acockburn/appdaemon:latest
    entrypoint: sh -c "sleep 30 && ./dockerStart.sh"
    restart: unless-stopped
    cpu_shares: 768
    mem_limit: 256m
    user: "994:994"
    networks:
      - default
      - internal
    ports:
      - "8180:5050"
    volumes:
      - /srv/hass/appdaemon:/conf
      - /srv/hass/secrets.yaml:/conf/secrets.yaml:ro
      - /etc/localtime:/etc/localtime:ro
    healthcheck:
      test: wget --quiet --spider --tries=1 localhost:5050 || exit 1
      <<: &default_healthcheck_options
        interval: 1m
        retries: 3
        start_period: 30s
        timeout: 30s
    depends_on:
      - hass

definitio avatar Jun 01 '21 11:06 definitio