RESTful API ignores conditions in automation

Hi,

I have the following automation, which works as expected when triggered by the device tracking.
The expected result is to turn on the driveway lights only after sunset when triggered by coming home.

The issue is that when this automation is called via the RESTful API, it ignores the condition and turns on the driveway light during the day!
Is this expected behavior, bug or quirk?

How do I use the RESTful API to only turn the lights on after sunset?

  - alias: Driveway lights ON at arrival
    trigger:
      platform: state
      entity_id: device_tracker.uksa007
      from: 'not_home'
      to: 'home'
    condition:
      condition: sun
      after: sunset
    action:
      service: light.turn_on
      entity_id: light.driveway_lights

I call the automation using the following API
Method: Post

http://ha.removed.com:8123/api/services/automation/trigger?api_password=removed

Json:
{"entity_id":"automation.driveway_lights_on_at_arrival"}

Thanks!

Manually triggering overrides the condition, it’s mostly used for testing, I would have your api call a script or change a Boolean rather than trigger.

Seems a bit daft that it overrides the condition, your not really testing anything apart from the action?

The action can be a whole script, so it s sometimes useful to be able to test them. Also if you’re triggering the automation directly it is assumed you want the event to happen.

Still seem daft to me, you “trigger” the automation, so it should do everything that it normally would if it was triggered normally.
The action, can normally be tested by using the developer tools, Services, states and events.

Using the API to trigger the automation is not testing it!

So to work around this behavior, I have created a new device_tracker.car and have the API changing the state of it.
The Automation trigger includes the new device_tracker.car.

This way I don’t need to duplicate the automation to a script.

So the car updates it’s state via the API and the automation triggers on the state change.
This might help someone in the future.

  - alias: Driveway lights ON at arrival
    trigger:
      platform: state
      entity_id: device_tracker.uksa007, device_tracker.car
      from: 'not_home'
      to: 'home'
    condition:
      condition: sun
      after: sunset
    action:
      service: light.turn_on
      entity_id: light.driveway_lights

http://ha.removed.com:8123/api/states/device_tracker.car?api_password=removed

Json:
{“state”: “home”}

1 Like