Automation triggers when Conditions aren't met

Yes, I did select “Reload Automations” under Server Controls after I changed the yaml file.
I believe that HA does that automatically when you change through the GUI.

Bullcrap on HA then If HA never tells me what conditions are true in the log for when it activates an automation how am I to figure out what is wrong.

It’s not worth using the HA App then. My wifes phone is currently on the kitchen table.
Google Maps says she’s at home (we share our coordinates).
But HA App says she is in the garage and has been for the last 16 minutes.

Can’t trust the app at all.

Is there a way to write HA code in python or some real language with proper encapsulation of statements instead of yaml?

It’s horrible that the indentation decides what goes together.

remove your conditions and call a python_script in your action section so you can use python to check conditions and be in full control of your automation.

Use the logbook.log service as one of the actions in the activating automation to establish what the conditions state is and why, or view the states section under Developer Tools to establish which condition(s) are the issue.

Do you have the YAML code for this?
Error while executing automation automation.if_phone_left_at_garage. Invalid data for call_service at pos 2: template value should be a string for dictionary value @ data[‘message’]

 data:
  message: {{ states.device_tracker.oneplus_a5000 }}
  entity_id: device_tracker.oneplus_a5000
  service: logbook.log

I don’t use it myself, but this thread has some.

Your error is related to using data when you need data_template I think.

1 Like

should be

data_template:
 message: "{{ states.device_tracker.oneplus_a5000 }}"
 entity_id: device_tracker.oneplus_a5000
 service: logbook.log

Thank’s,

all I get is

Logger: homeassistant.components.automation
Integration: Automation (documentation, issues)
First occured: 6:42:35 AM (1 occurences)
Last logged: 6:42:35 AM

Error while executing automation automation.if_phone_left_at_garage. Invalid data for call_service at pos 2: required key not provided @ data['name']

Is my notification code malformed somehow, it does work.

- id: '1582752041728'
  alias: If Phone left at garage
  description: ''
  trigger:
  - entity_id: binary_sensor.sensor_hallen_motion
    platform: state
    to: 'on'
  condition:
  - condition: or
    conditions:
    - condition: state
      entity_id: device_tracker.max_oneplus5
      state: Garaget
    - condition: state
      entity_id: device_tracker.oneplus_a5000
      state: Garaget
    - condition: state
      entity_id: device_tracker.sm_g950f
      state: Garaget
  action:
  - data:
      message: Mobilen är kvar i bilen
      title: Mobil i bilen!
    service: notify.mobile_app_oneplus_a5000
  - data_template:
      message: "{{ states.device_tracker.oneplus_a5000 }}"
      entity_id: device_tracker.oneplus_a5000
    service: logbook.log

Looking at the services tab under Developer Tools in one of my HA instances, the logbook.log service requires a name parameter (not marked with optional):

I would try something like

  - service: logbook.log
    data_template:
      name: "OnePlus A5000 Device States"
      message: "{{ states.device_tracker.oneplus_a5000 }}"
      entity_id: device_tracker.oneplus_a5000
1 Like

AppDaemon

but it the TS cannot find out why the automation failed…

He asked for a way to write code in Python and I provided a solution :wink: If he writes the automation in AppDaemon, he can easily check with log messages what doesn^'t work.

Thanks,

I’m already regretting my choice of Home Assistant.

Why? I just showed you a way to create Home Assistant automations completely in Python.

What were your other choices?

Python, like YAML, relies on indentation to “decide what goes together”.

Perhaps you’d prefer Java? If so, the openHAB community may be the better choice for you.

1 Like

There weren’t any… (I could have bought a solution) I would be much more OK with Home Assistant if the Documentation actually matched what the program actually does.

But all this, HA will trigger this automation on a value that isn’t really what the conditions states updated because it clearly states in HA logs that we are actually home and not in the Garage, It’s just horrible.

And no one seems bothered by the actual condition not being met.

Please try this:

- id: '1582752041728'
  alias: If Phone left at garage
  description: ''
  trigger:
  - entity_id: binary_sensor.sensor_hallen_motion
    platform: state
    to: 'on'
  action:
  - service: persistent_notification.create
    data_template:
      title: "Test"
      message: >
        {% set sm950 = states('device_tracker.sm_g950f') %}
        {% set a5000 = states('device_tracker.oneplus_a5000') %}
        {% set oneplus5 = states('device_tracker.max_oneplus5') %}
        {{ "sm_g950f is " + sm950 + " / a5000 is " + a5000 + " / oneplus5 is " +oneplus5 }}

And show the resulting persistent_notification in the situation that you think your automation should not trigger.

Thanks for trying to help!

This is the result I get.

title: Test
message: sm_g950f is home / a5000 is home / oneplus5 is home

It should NOT trigger if the state is like above. Ever.

it should trigger on

sm_g950f is Garaget
OR
a5000 is Garaget
OR
oneplus5 is Garaget

The last two (a5000 and oneplus5) are really the same device, the only thing is that a5000 is from HA-app and oneplus5 is OwnTracks

So the code from this post

Sends the notification in the current situation??

Actually, there are several other solutions, both free and paid.

openHAB
Domoticz
iobroker
Homeseer
Hubitat
etc

You should try some of them and see which is a better fit for you. From your community profile, it appears you’ve used Home Assistant since October 2019. Yet the word you’ve used to describe it has been “horrible” (and used much more than once). Why suffer with this “horrible” product when something else might suit you better?