What am I doing wrong in my automation (most likely condition misunderstanding...)?

My config look like this:

 - alias: "Open shutters in the morning if motion detected"
   trigger:
      platform: state
      entity_id: binary_sensor.fibaro_system_fgms001_motion_sensor_sensor_24_0
      to: 'on'
   action:
    - condition: template
      value_template: '{{ states.cover.fibaro_system_fgrm222_roller_shutter_controller_2_level_21_0.attributes.current_position < 95 }}'
    - condition: time
      after: '07:20:00'
    - condition: time
      before: '11:00:00'
    - service: homeassistant.turn_on
      entity_id: script.shutter_living_up

Today I detected the following happening: The shutter went up in the morning after it detected me. In the evening I get back from work and as it darkens I press the shutter down button in the wall. The shutter goes down for probably about 5-10% (first condition?) and then the shutter gets up again to be fully opened to then just go down again to close fully! I tested once and the shutter went 5% down, went up and then down to 100% closed and then (that was special!) it went up again to fully openedā€¦

For testing purposes I changed the condition time before to 21:00 and triggered the automation by walking by the motion sensor. Then I disabled the automation at the time where the shutter went up fully. Then I pressed the shutter button and the shutter went down as it should. So everything is fine when the automation is deactivatedā€¦ Not a problem of the fibaro shutter as it seems.

Anyone any Idea?

Thank you very much for any clue!

Try moving your conditions to their own stanza, and see if it behaves better. Looks like you currently have them in the ā€˜actionā€™ stanza. Here is the relevant documentation page: https://home-assistant.io/getting-started/automation-condition/

Something along the lines of this: (untested)

 - alias: "Open shutters in the morning if motion detected"
   trigger:
      platform: state
      entity_id: binary_sensor.fibaro_system_fgms001_motion_sensor_sensor_24_0
      to: 'on'
   condition:
     conditions:
      - condition: template
        value_template: '{{ states.cover.fibaro_system_fgrm222_roller_shutter_controller_2_level_21_0.attributes.current_position < 95 }}'
      - condition: time
        after: '07:20:00'
      - condition: time
        before: '11:00:00'
   action:
    - service: homeassistant.turn_on
      entity_id: script.shutter_living_up
1 Like

A condition is not an action. It must be separat under trigger

Edit: to slow^^

1 Like

The HA site cites that conditions can be in the action section. See the bottom of this page.

I have been meaning to test if this even works and possibly update the page as needed.

1 Like

Ok you are right. Sorry. I have no solution.
All my automation are like @Zen example and they are working fine.

Ive seen this come up a few times, it seems that putting the conditions in the actions either a) doesnā€™t work as you and I suspect or b) needs some notation added as a number of people are running into the issue.

My solution to the issue is the same as yours and Zens. I know that method works.

4 Likes

Yeah, add my voice to the choir here. I gave up trying to make them work and use the same method and run into less issues trying to make things work and more time enjoying automations. :wink:

2 Likes

Thanks a lot taking time to help me @zen @kolossboss @silvrr @rpitera !

I followed the documentation that silvrr linked above. Iā€™ill try it with a separate conditions stanza and report back here.

Does someone of you know how to limit the execution of an automation to once per day/hour?

I have a rain notification that I like to limit to no more than once every thirty minutes. This is the quick and dirty way I do it - no doubt others will show you their way as well. In my case, I just turn off the automation and add a delay as one of the actions. Then after the delay I turn it back on.

# Rain Alert

- alias: 'Raining'
  trigger:
    platform: state
    entity_id: sensor.dark_sky_precip_intensity
    from: '0'
  action:
    - service: tts.google_say
      entity_id: media_player.living_room_home
      data_template:
        message: 'Excuse me Robert, but is currently {{ states.sensor.dark_sky_precip.state }}ing and it is {{ states.sensor.dark_sky_temperature.state | int }}degrees outside.  Forecast says {{ states.sensor.dark_sky_minutely_summary.state }}.'
        cache: false
    - service: automation.turn_off
      entity_id: automation.raining
    - delay: 00:30:00
    - service: automation.turn_on
      entity_id: automation.raining
1 Like

Thatā€™s an elegant way! Didnā€™t think it through this way :slight_smile: Itā€™s obvious I donā€™t have the the full overview of all the HASS components.

Something Iā€™am trying at the moment is:

 - alias: "turn off stair ligth after 10 minutes without motion"
   trigger:
    platform: template
    value_template: "{{ as_timestamp(now()) - as_timestamp(states.binary_sensor.fibaro_system_fgms001_motion_sensor_sensor_14_0.last_changed) > 600 }}"
   action:
    - service: switch.turn_off
      data:
         entity_id: switch.fibaro_system_fgs223_double_relay_switch_28_0

So the key is a value_template:
value_template: "{{ as_timestamp(now()) - as_timestamp(states.YOUR-ENTITY-ID.last_changed) > 600 }}"

For 24h it has to check against 86400 seconds. Itā€™s a start but not much moreā€¦ The condition checks the time from last change and this is not always the same moment. I have to think about an aditional ā€œor conditionā€ to reenable my automation somehow.

I think Iā€™m going off topic now. Iā€™ll open another thread if there is nothing in the forum.

The code that works now looks as follows:

 - alias: "Open shutters in the morning if motion detected"
   trigger:
      platform: state
      entity_id: binary_sensor.fibaro_system_fgms001_motion_sensor_sensor_24_0
      to: 'on'
   condition:
     condition: and
     conditions:
      - condition: template
        value_template: '{{ states.cover.fibaro_system_fgrm222_roller_shutter_controller_2_level_21_0.attributes.current_position < 95 }}'
      - condition: sun
        after: sunrise
      - condition: sun
        before: sunset
   action:
     - service: homeassistant.turn_on
       entity_id: script.shutter_living_up

Thanks again at @zen @kolossboss @silvrr @rpitera!

2 Likes

Ok. It was too early to give the all-clearā€¦ Problem persists. Iā€™am working on this automation now:

#Open shutters in the morning if motion detected
 - alias: "a_shutter_1"
   trigger:
      platform: state
      entity_id: binary_sensor.fibaro_system_fgms001_motion_sensor_sensor_24_0
      to: 'on'
   condition:
      condition: and
      conditions:
      - condition: template
        value_template: '{{ states.cover.fibaro_system_fgrm222_roller_shutter_controller_2_level_21_0.attributes.current_position < 95 }}'
      - condition: time
        after: "06:30:00"
      - condition: time
        before: "11:00:00"
   action:
     - service: homeassistant.turn_on
       entity_id: script.shutter_living_up
     - service: automation.turn_off
   entity_id: automation.a_shutter_1
#small delay time for testing purposes
 - delay: 00:01:00
     - service: automation.turn_on
       entity_id: automation.a_shutter_1

Beforehand Iā€™am confused about conditions:

Is this ok?

   condition:
     conditions:
      - condition: ...
      - condition: ...
      - condition: ...

Or do I need:

   condition:
     condition: and
     conditions:
      - condition: ...
      - condition: ...
      - condition: ...

Itā€™s my understanding that condition: and connects all child conditions with an logical and. So the result is only true if everything is true.

The first scheme does not work. It says mapping not allowed.

Second works but the shutters run crazy as initially posted: I can reconstruct the behavior most of the time. I let trigger the automation by moving by the motion sensor and wait till the shutters are up. Then I wait past the before time (11:00:00) press the shutter to go down and go by the motion sensor to trigger the automation again while the shutter is moving down. And tada: The shutter suddenly (or not suddenly, itā€™s the motion sensor I suspect!) goes up completely first (while it was going down!). At top arrived it starts rolling down again.

Now everything works again as expectedā€¦ I donā€™t understand it anymore. Perhaps the upgrade of HASS changed something. I have to observe more and come back again.

Yesterday I had a lot of ghost movement again. Nothing was in the logs and specially no z-wave commands were sent. It had to be the fibaro device itself.

Searching the web gave a clue (donā€™t know anymore where I found it): set parameter 29 - the calibration mode - of the devices manually to 0. The manual says the parameter 29 is automatically set back to 0 after you changed it to 1. In calibration mode your fibaro device goes up once and down once.

Perhaps this problem is solved with newer firmware. At the moment there is no existing solution that I know of to update the firmware of fibaro devices without using fibaroā€™s home center.

Long story short: Change parameter 29 to 0 manually for your fibaro fgmr-222 / fgr-222 if you have ghost movements.

Two months later I still have ghost movements. I think my shutter devices randomly start to calibrate themselvesā€¦ No idea why.

@Zen: You have fibaro shutters, donā€™t you? Have you never seen ghost movements or unwanted calibrations?

I am desperate. Perhaps I need to upgrade the firmware. But Iā€™m not aware of any upgrade function without involving a fibaro home center. Thatā€™s an enormous disadvantage of fibaro devices.