Could I have someone smarter than myself (it doesn’t take much, haha) help me figure out what’s causing the errors below. I will paste the automation code first. and then the 2 errors in code positions 2, and 3. Thank you all for all of the assistance you have given me in the last little bit with regards to coding. I am very appreciative of it.
Automation:
alias: Security Breach Doors
trigger:
- platform: state
entity_id:
- binary_sensor.front_door
- binary_sensor.back_door
- binary_sensor.garage_entry_door
to: "on"
condition:
- condition: state
entity_id: input_boolean.sentry_mode
state: "on"
action:
- choose:
- conditions:
- condition: template
value_template:
'{{ trigger.to_state.attributes.friendly_name == "Back Door"
}}'
- condition: state
entity_id: input_boolean.dog_mode
state: "on"
sequence:
- service: script.text_notify
data:
who: "parents"
message: "Dog Mode enabled, bypassing back door sensor."
default:
- service: script.jarvis_alert
data_template:
message: "My security protocols are being overidden,, The {{ trigger.to_state.attributes.friendly_name }} has been opened."
- service: script.text_alert
data:
who: parents
title: "Security Alert!!"
message: "{{ trigger.to_state.attributes.friendly_name }} has been opened."
- service: input_boolean.turn_on
entity_id: input_boolean.security_issue
initial_state: true
Error in log 1:
Logger: homeassistant.components.automation.dog_mode_activated_test
Source: helpers/script.py:1718
Integration: Automation ([documentation](https://www.home-assistant.io/integrations/automation), [issues](https://github.com/home-assistant/home-assistant/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+automation%22))
First occurred: 9:21:38 PM (6 occurrences)
Last logged: 9:25:04 PM
* Security Breach Doors: Choose at step 1: default: Error executing script. Error for call_service at pos 1: Error rendering data template: UndefinedError: 'dict object' has no attribute 'to_state'
* Security Breach Doors: Error executing script. Error for choose at pos 1: Error rendering data template: UndefinedError: 'dict object' has no attribute 'to_state'
Error in log 2:
Logger: homeassistant.helpers.template
Source: helpers/template.py:1862
First occurred: 9:21:38 PM (6 occurrences)
Last logged: 9:25:04 PM
* Template variable error: 'dict object' has no attribute 'to_state' when rendering '{{ trigger.to_state.attributes.friendly_name == "Back Door" }}'
* Template variable error: 'dict object' has no attribute 'to_state' when rendering 'My security protocols are being overidden,, The {{ trigger.to_state.attributes.friendly_name }} has been opened.'
If you are testing this by running it manually there will be no trigger state object for your templates. You need to change the state of the binary sensors to cause the automation to run.
@tom_l My gracious, I wasn’t even thinking about that (That’s exactly what I was doing). Thank you so much for pointing that out. I really do appreciate it Tom. I was setting here beating my head against the wall wandering why I was getting errors. What you say makes perfect sense. I’m sorry some of the things I post here are dumb sometimes. I definitely still learning.
Again, thank you so much Tom!!
Thank you for showing me that with the template format also. Def see the issue with that once you caught it.
And to add to Toms answer, take note of the state the binary_sensorreally sends. I had it once or twice, that “on” or “off” didn’t work, as my binary_sensors sent “open” or “close”. As yours are doors as well and if you have set the correct device_class…
EDIT: I misremembered, sorry! Just forget what I’ve said, it was simply wrong! Sorry!
Binary sensors can only be on or off. It’s impossible for them to be any other state excluding unknown or unavailable. The device class changes the display in the front end and the icon, it does not change the backend state.
Thank you for clarifying @paddy0174’s response, I thought that was the case. This will be useful for others in the future when they see this quick thread.
Thank you all again for how helpful you are, all the time honestly. I’m definitely learning alot from all of you each day.
@paddy0174 Thank you for bringing this concept up. This is something new users should be aware of also. @petro clarified things a bit for others who may read this.
That’s what I thought, and in theory that is totally correct. But I had it once or twice with a binary_sensor, that my template didn’t work as expected, turns out it was the state not being reported as “on” or “off”, but rather as “open” and “closed”.
I’ll need to search for it, but as far as I remember, it was a binary_sensor for a door contact. I’ll see if I can find it.
You can save your time by not looking. There’s nothing to prove. The code literally makes it impossible. In the early days, integrations made sensors when they should have been binary_sensors. I can 100% guarantee you’re miss remembering. Or you’re remembering a cover entity.
No, no, that won’t let me sleep at night, despite knowing (and reading) you’re right.
But I found it in the meantime, and yes, I misremembered… It was with binary_sensors coming from ESPHome turned into device_trackers… and these didn’t work as expected, because the device_tracker is home/away and not on/off as the “real binary_sensors”.
@wtstreetglow Sorry for the confusion, as I said, I misremembered or better confused things… Sorry about that, I’ll correct my post above, and you, please don’t remember my post.