Automation triggers when Conditions aren't met

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?

Because HA seemed to have the largest user base and the easiest setup…

I’m on my 4th reinstall of HA, since there were multiple ways of installing HA I tried a few.
This is basically the first time I actually let HA be in control of my home with automations replacing Hue and Tellstick.

It’s really difficult to understand how to write any entry when the documentation says one thing and the automatically generated code from the GUI is totally backwards from the documentation.

Also I have to commend the fact that more time is given to the fact that my user experience is horrible and that I should just go somewhere else, instead of fixing what is wrong…

Yes! That has been the problem all along.
The condition is ONLY when the state (or zone previously) is Garaget should the notification be sent. But it’s constantly being sent whenever someone walks past the sensor.

It just seems to me that you must be having a miserable time with Home Assistant because each time you refer to it your description includes the word “horrible”. Truly, why suffer with all of its horribleness when other solutions might be a better fit?

On the other hand, if you want to make Home Assistant less “horrible”, then contribute to it. It’s a community-driven project so if the documentation needs correction, fix it. If something doesn’t work properly, report it as an Issue in the Github repo or, if you have the requisite skills, fix it via a Pull Request.

Home Assistant’s refinement is driven by the community. Complaining about its deficiencies may be carthartic but it won’t move the ball forward. In addition, constant complaining tends to alienate others, notably the people who can provide assistance.

2 Likes

Hmm, this should be impossible, let’s check like this:

- 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
  - 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 }}

If this triggers and you get the message and the persistent notification shows that all three device_trackers are home, then there’s an issue with HA. But I doubt that this is possible and if it is I will try to reproduce the situation and file an issue on Github, because this would be a major issue.

Well Taras,

I would, I actually like writing documentation. But to write documentation I need to have a clear view of how stuff works and what is the correct way of doing things.

When I can’t figure that out, and the application can’t tell me. I can’t do it.
Today I learned that “Developer Tools” in the menu, isn’t Developer Tools. It’s Necessary tools for using the application, you wont get by without them… Which is great!

Now I have to try what @Burningstone suggested.

ok, this is seriously giving me gray hairs.
I hadn’t looked at HA since I confirmed the last code bit you gave me.
I had 24 persistent notification from labeled Test all of them with home as state for all three devices. Spread out over a 7 hour period. Sadly I don’t have a screenshot of that. Something triggers the Automation, that’s for sure.

The log for two of them looks like this:

So I enter this new code, and I reload automations and Execute the code from the Automations page. OOOOooh I got a new notification both on my device and in HA…
But then the QA-staff in me just googled “home assistant automation trigger manually” and loo and behold. Execute doesn’t EVEN CONSIDER THE CONDITIONS, it just runs the Action… how… I can’t even find the words…

  1. How am I supposed to test ANY automation at all?
  2. Why doesn’t it consider conditions of the automation?
  3. Iff it’s supposed to be like this, Change Execute to “Run Action” instead.

So @Burningstone I don’t know what is wrong, only that something is. I restarted the server too just to be sure.
Standing and waving in front of the sensor doesn’t seem to do anything right now (which is great) but it didn’t do that before either, so I have to just wait for the conditions to arise again. If it happens 3 times an hour when my kids are awake it should happen tomorrow.

Edit: When I pull data from Grafana it tells me this:

Time state friendly_name_str
2020-03-08 17:09:33 home oneplus_a5000
2020-03-08 17:09:20 home SM-G950F
2020-03-08 17:08:23 Garaget oneplus_a5000
2020-03-08 17:05:46 home SM-G950F
2020-03-08 17:03:57 home SM-G950F
2020-03-08 17:01:27 not_home SM-G950F
2020-03-08 16:44:37 not_home SM-G950F
2020-03-08 16:42:49 not_home oneplus_a5000

Which means that actually none (well 3 since 3 of them where manual) of the 24 activations are correct.
image
Although ALL notifications stated that the devices where at home
At 05:07:17 the data clearly states oneplus_a5000 as “not_home”

Why didn’t you tell us that you execute it manually? Would have saved us all a lot of time…

Via trying and reading error messages and through “tricks” like shown in this thread such as creating logbook entries or persistent notifications.
I do my automations for HA in AppDaemon, thwre I can put logs and debug where I want easily.

1 Like

Just a guess but possibly because it was overshadowed by efforts to describe Home Assistant’s horribleness.

Kudos to you Burningstone for demonstrating infinite patience. It’s likely this will be revealed to be a PEBKAC situation but it’s going to take more of your patience to discover it. Best of luck; I’m rooting for your success.

Just a guess but if you Taras had contributed to actually solving the problem instead of trying to make me switch home automation platform you could have asked me how I tested this.

And I just told you that I activated it through the Automations, 3 out of 24 times. The other 21 times the automation activated by itself although the conditions were not met. Like I proved with actual data!

Please enlighten me how I’m supposed to infer that pressing Execute on an Automation SKIPS verifying the Conditions and goes directly to activate the action.

It’s in the Testing your Automation section of the Automations Troubleshooting documentation (emphasis seen below is not mine but exactly as shown in the documentation):

Please note that if you click on Trigger of an automation in the frontend, only the action part will be executed by Home Assistant. That means you can’t test your trigger or condition part that way. It also means that if your automation uses some data from triggers, it won’t work properly as well just because trigger is not defined in this scenario.

Feel free to check my profile to confirm that I’ve volunteered my time to help hundreds of other people. I pick and choose the ones that interest me and the degree of my involvement. This one interested me initially but the unrelenting negative attitude extinguished it. I’ll hazard a guess that it had the same effect on others.

I’ve used software that I disliked so I chose something that was a better fit for me. That decision served me well so, given your expressed discontent, it was my advice to you.

Good luck.

3 Likes