Autonomation, from form

Hello,

For my robomower i want it to mow for 45 minutus when it havent mowed yesterday (with the stock app schedule bacause of tome options), also mow now when there is a rainchange more than 10% tomorow.
-Can someone tell me if this is right,or do i need an % karakter in it?
-also, the triggers, does it go off when there all true, or just 1 of them?
i cant test it easy, can someone conform if this is right?
Thanks in advance

  alias: Grasmaaien
  description: ''
  trigger:
  - event: sunset
    platform: sun
  - at: '20:30'
    platform: time
  - entity_id: sensor.br_rainchance_1d
    from: '10'
    platform: state
  condition:
  - condition: template
    value_template: "        {% set last_run = state_attr('landroid_cloud.start',\
      \ 'last_triggered') %}\n        {{ last_run is none or (now().date() - last_run.date()).days\
      \ >= 1 }}"
  - condition: and
    conditions:
    - condition: not
      conditions:
      - condition: state
        entity_id: sensor.landroid_maaike_error
        state: Rain delay
  action:
  - data: {}
    service: landroid_cloud.start
  - timeout: '45'
    wait_template: ''
  - data: {}
    service: landroid_cloud.home

Please see the pinned message for how to correctly format code. Without you doing that it’s hard to follow the code.

For triggers… it’s explained here:

When any of the automation’s triggers becomes true (trigger fires), Home Assistant will validate the conditions, if any, and call the action.

Think of triggers & conditions this way.

Triggers are events (things that happen.) If you have more than one trigger, any one of them happening can cause the automation’s actions to run. So in your post, they are “sun setting”, “clock reaching 20:30”, “sensor.br_rainchance_1d's state changing from '10' to some other value.”

Conditions test the current state of the system. They are evaluated when one of the triggers “fires.” If true then the actions run. If not, then the actions don’t run.

So, think about when you want the actions to run. Then create a trigger for each of those events.

Next, think about what the state of the system must be for the actions to run when one of the triggers “fires.”

So putting that together, the actions run if the condition(s) is/are true when one of the trigger events occurs.

2 Likes

If you need an “and” function on a trigger you may need to try a template.

trigger:
  platform: template
  value_template: >
    {{ is_state('switch.living_room', 'on')
    and is_state('switch.house', 'off')
    and not is_state('sensor.motion', 'off')
    and is_state_attr('climate.thermostat', 'preset_mode', 'away')
    }}

This gives a few examples of ands with ‘not’ and added attributes.

Or just use conditions :wink:

This topic makes me think of the consequences of a robotic mower let loose by an imperfect automation.

Thanks all.

Taras, why do you think its imperfect, and what consequences?

I don’t think there’s a suggestion that your automation is necessarily imperfect. As to consequences,

image

1 Like

What Troon said.

My point was that the consequences of a bug in an automation that controls damage-inflicting devices are potentially greater than, say, a buggy automation that controls lighting. It doesn’t have to be a robotic mower, a remotely-operated garage door can have undesirable consequences or even a thermostat (that fails to heat an unoccupied vacation home in the dead of winter). Some automations just need extra care to handle various edge-cases to ensure they don’t cause costly (or even tragic) incidents.

There is indeed an advert in the UK to that end :wink:

1 Like

I simplified a bit of this for you. I think you really need to work out the exact syntax of what you want this to do. Triggers are (or) by nature FYI. It’s best to wear out unwanted triggers in Conditions, not in overly complicated trigger templates. I have had people help me through that mistake plenty of times. Maybe consider a {% if … %} {% else %} {% endif %} structure for one condition template that incorporates the previous mowing state and your rain trigger.

- alias: Grasmaaien
  trigger:
  - platform: sun
    event: sunset
  - platform: time
    at: '20:30
  - platform: numeric_state
    entity_id: sensor.br_rainchance_1d
    above: 10
  condition:
    condition: and
    conditions:
      - condition: template
        value_template: >
          {% set last_run state_attr('landroid_cloud.start', 'last_triggered') %}
          {{ last_run is 'none' or (now().date() - last_run.date()).days  >= 1 }}
      - condition: template
        value_template: >
          {{ not is_state('sensor.landroid_maaike_error', 'Rain Delay') }}
  action:
  - data: {}
    service: landroid_cloud.start
  - timeout: '45'
    wait_template: ''
  - data: {}
    service: landroid_cloud.home

This is a tag on from my last post. This is not code but more a map of what I would do.

Notice, for safety sake I added an input boolean that would allow you to create a rain delay or yard work delay ect of your own.

Also, if you get on/off state information from you mower, again for safety, I would creat a second automation that tests to make sure that the turn off command ran. A lot can happen in 45 minutes.
trigger ‘21:16:00’
condition: is_state(mower, on)
action: mower home

trigger:
  - platform: time
    at: '20:30:00'
condition:
  condition: and
  conditions:
    - condition: template
        {{ is_state('input_boolean.overide', 'off' ) }}
    - condition: template
        {% if is_state('entity.id', 'Rain Delay') %}
          false
        {% else %}
            {% if (time since last mow)|float >= 1 %}
              true
            {% elif (chance of rain tomorrow)|float > 10 %}
              true
            {% else %}
              false
            {% endif %}
        {% endif %}
action:
    - service: landroid_cloud.start
    - delay:
        minutes: 45
    - service: landroid_cloud.home

Thanks for all the info! I will try to implement it