Trigger.to_state.name is "unknwon".... entity_id too?!?!?

I have an automation that triggers my alarm. I want to write the entity_id or friendly name to a input_text object so I can use it in my notification automation. The problem is the value is always “unknown”.

So essentially trigger.to_state.name is unknown… same for the entity_id too. I’ve copied my automation below… I’ve got about 15 sensors so I removed all but 2 of them to keep this short. Any ideas?

I’ve read the trigger/state docs… this should be so easy, got me pulling my hair out.

- alias: Trigger alarm while armed away
  trigger:
  - platform: state
    entity_id: sensor.hallway_motion_sensor
    to: '8'
  - platform: state
    entity_id: sensor.conservatory_motion_sensor
    to: '8'
  condition:
  - condition: state
    entity_id: alarm_control_panel.home_alarm
    state: armed_away
  action:
  - service: input_text.set_value
    data_template:
      entity_id: input_text.trigger_source
      value: "{{ trigger.to_state.name }}"
  - service: alarm_control_panel.alarm_trigger
    entity_id: alarm_control_panel.home_alarm

How did you test the automation? Did you execute it manually? If you execute it manually, it will always be unknown, as there was no trigger. You could also try
{{ trigger.to_state.attributes.friendly_name }}

Also, are you using Aeotec Multisensors? I’m assuming from the to: '8', if these are indeed Aeotec Multisensors, you need to change the reporting to binary reporting to get a binary sensor for motion instead of this sensor that shows some int based on the type of activity detected.

I triggered the automation by arming the alarm and then setting it off… good suggestion however I was aware about the issue with manually triggering it.

The motion sensors are simply some generic Chinese make. No idea why but they go from 0 to 8 when motion is detected. I had to use them as they’re pet friendly so the cats don’t set them off. They’ve worked well thus far, I’ve not set up any binary reporting (not sure what you mean) as they work.

For all intent and purposes it simply looks like the trigger.to_state object is null when the automation triggers, which I know is essentially impossible… hence me fishing just to see if anyone else has encountered this before.

As I said the alarm triggers so the automation most certainly works.

Great, so we can cross this off the list.

Ok, this is fine. FYI there are some motion sensor like the Aeotec that I mentioned, which have a special setting for motion reporting to have a binary sensor in the end instead of the sensor with 0 and 8.

Can you please try writing the message to a persistent notification instead of the input text like this:

service: persistent_notification.create
data:
  message: "{{ trigger.to_state.attributes.friendly_name }}"
1 Like

Ok, my home assistant has left me looking like a fool. I had tried your suggestion trigger.to_state.attributes.friendly_name a fair while ago, however I just added your persistent notification and what do you know, it worked… also what do you know 2, my input_text entity was updated too! along with my alarm triggered notification… all working perfectly?

I have no idea why its started working all of a sudden but many thanks for you help!

1 Like