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