Why does this error appear on the trigger.entity_id, even when it triggers on that entity

Tags: #<Tag:0x00007f73a6327500> #<Tag:0x00007f73a6326358>

Think I finally find the source for an very frequent error I have been hunting for very long, 'None' has no attribute 'entity_id':

I’ve added an extra condition to test for the existence of trigger.entity_id now so it won’t execute the action block if trigger.entity_id is none:

      - condition: template
        value_template: >
          {{trigger.entity_id is not none and
            trigger.to_state.state is not none and
            trigger.from_state.state is not none and
            trigger.to_state.state != trigger.from_state.state}}

but I dont understand why this helps. If the automations triggers, it will always have an entity_id? How come this automation would trigger and still have the error appear?

  - alias: Presence Tracking
    id: Presence Tracking
    trigger:
      platform: state
      entity_id:
        - group.daughter1
        - group.daughter2
        - device_tracker.daughter4
        - group.daughter3
        - device_tracker.she
        - device_tracker.me
    condition:
      - condition: template
        value_template: >
          {{trigger.entity_id is not none and  # <---- added this line and the error disappeared
            trigger.to_state.state is not none and
            trigger.from_state.state is not none and
            trigger.to_state.state != trigger.from_state.state}}
      - condition: template
        value_template: >
          {% set zones = states.zone|map(attribute='name')|list %}
          {{trigger.to_state.state in ['home','not_home'] or
            trigger.from_state.state in ['home','not_home'] or
            trigger.to_state.state in zones or
            trigger.from_state.state in zones}}
      - condition: template
# https://community.home-assistant.io/t/how-to-check-greater-than-of-last-status/65854/3
        value_template: >
          {{(now() - trigger.from_state.last_changed
            |default(0)).total_seconds() > states('input_number.presence_timer')|int}}
    mode: queued
    action:
      - service: script.intercom_presence
        data_template:
          message_nl: >
            {% set entityid = trigger.entity_id %}
            {% set tostate = trigger.to_state.state %}
            {% set fromstate = trigger.from_state.state %}
            {% set name = trigger.to_state.name %}

              Hi, op {{as_timestamp(now())|timestamp_custom('%X')}},
            {% if tostate == 'not_home' %}
              vertrok {{-name }} van {{fromstate}}
            {% elif fromstate == 'not_home' %}
              kwam {{-name }} aan bij {{tostate}}
            {% else %}
              vertrok {{-name }} van {{fromstate}} en kwam aan bij {{tostate}}
            {% endif %}

          message_en: >
            {% set entityid = trigger.entity_id %}
            {% set tostate = trigger.to_state.state %}
            {% set fromstate = trigger.from_state.state %}
            {% set name = trigger.to_state.name %}

              Hi, at {{as_timestamp(now())|timestamp_custom('%X')}},
            {% if tostate == 'not_home' %}
              {{-name }} left {{fromstate}}
            {% elif fromstate == 'not_home' %}
              {{-name }} arrived at {{tostate}}
            {% else %}
              {{-name }} left {{fromstate}} and arrived at {{tostate}}
            {% endif %}

      - service_template: >
          script.{% if is_state('input_boolean.notify_announcement','on') %}announce_presence
                 {% elif is_state('input_boolean.notify_presence','on') %}notify_presence
                 {% else %}dummy
                 {% endif %}
        data_template:
          trigger: Presence tracking
          entityid: '{{trigger.entity_id}}'
          tostate: '{{trigger.to_state.state}}'
          fromstate: '{{trigger.from_state.state}}'

I didn’t look at the whole automation, but in this part:

      - condition: template
        value_template: >
          {{trigger.entity_id is not none and
            trigger.to_state.state is not none and
            trigger.from_state.state is not none and
            trigger.to_state.state != trigger.from_state.state}}

The second & third lines of the template are wrong. And I don’t think you need the line you added. So:

      - condition: template
        value_template: >
          {{trigger.to_state is not none and
            trigger.from_state is not none and
            trigger.to_state.state != trigger.from_state.state}}
1 Like

ok thanks! will adapt immediately and check what happens :wink: (since adding the line made the error disappear, it must have guarded something the others didnt catch)

update:

immediately after reloading:

hey Phil,

been changing those conditions, but am not confident I understand why it would be ‘wrong’, (they have worked for over 2 years like this (of course with the more recent issue of the posted error…))

also I searched my memory and found what I was looking for: Template automation for my boiler

how come you now feel this is wrong?

When a state trigger fires the trigger variable will have the fields defined here.

The values of trigger.from_state and trigger.to_state depend on the before & after states of the entity that changed state. When the entity is created trigger.from_state will be none because it’s state did not exist before. When the entity is removed trigger.to_state will be none because it’s state was deleted from the system.

If, e.g., trigger.from_state is none then the expression trigger.from_state.state will cause an error because you’re trying to access the state attribute of trigger.from_state, but since trigger.from_state is none it does not have a state attribute.

You have to check if trigger.from_state is none. It doesn’t make any sense to check if trigger.from_state.state is none because 1) that can cause an error as I just explained, and 2) if trigger.from_state is not none, then trigger.from_state.state will never be none, because an entity’s state can never be none; it will always be a string. (And, BTW, none is not the same thing as an empty string, just in case you were wondering.) As I said before, trigger.from_state.state|default('some value') would be valid, but not trigger.from_state.state is not none.

Referring to some conversation that happened a year ago doesn’t really help here. Things have changed, and certainly my understanding of things has also changed significantly. That’s not to say that everything I said back then was wrong, (or everything I say now is right, for that matter) just that it’s certainly possible some were. :slightly_smiling_face:

Now, regarding the “Error during template condition: UndefinedError: ‘None’ has no attribute ‘entity_id’” error, that is strange. That is saying the trigger variable itself was None. That, of course, should never happen. BUT, I have seen another report of this, but I was never able to reproduce it. What version are you using? For reference, see Issue #38433

The only other thing I’d suggest changing in your automation is this:

        value_template: >
          {{(now() - trigger.from_state.last_changed
            |default(0)).total_seconds() > states('input_number.presence_timer')|int}}

There’s absolutely no reason to use the default filter here. First, trigger.from_state will have already been verified to be not none, so trigger.from_state.last_changed will always be a valid datetime object. Second, the default filter only applies when the “input” is not defined, but as I said, it will be defined, so it has no effect. And third, even if it did apply, the default value – 0 – is useless here, as you can’t subtract an int from a datetime; that would still cause an error.

Are you absolutely sure the error you’re seeing is due to this automation? How have you verified which automation caused the error?

Actually, are you even sure this is happening in an automation and not in a script?

Also, do you use any of the new style device triggers? If so, which one(s)?

The error you posted only says the error occurred while evaluating a template condition. It doesn’t say anything about what that condition template was in.

Before we can get to the bottom of this, you have to verify what was executing when that error occurs. I think the only way you’ll be able to determine that is to look in home-assistant.log.

I wouldn’t bet my life on it, but, it disappeared during regular operation after having added the line I showed above.

same answer, no not 100% sure. even worse when clicking reload scripts, I see this now:

Error during template condition: UndefinedError: 'None' has no attribute 'context'

which can only be caused by this automation, since it is the only automation or script using the ‘context’.

  - alias: Person forward intercom messages to filed intercom messages
    id: Person forward intercom messages to filed intercom messages
    trigger:
      platform: state
      entity_id: script.intercom_text_message
    condition:
      condition: template
      value_template: >
        {{states.script.intercom_text_message.context.user_id != None}}
    action:
      service: notify.filed_intercom_messages
      data_template:
        message: >
          {% set message = states('input_select.intercom_message') %}
          {% set device = states('input_select.intercom') %}
          {% set language = states('input_select.intercom_language') %}
          {% set id = trigger.to_state.context.user_id %}
          {% set time = as_timestamp(now())|timestamp_custom('%d %b: %X') %}
          {% set user = states.person|selectattr('attributes.user_id','eq',id)|first %}
          {% set user = user.attributes.friendly_name %}
          {{time}}: {{user}} played "{{message}}" on {{device}} in {{language}}

Ive even added a condition (probably not the correct one) to prevent that, which it had, except for the reloading of automations/scripts…

Yes I know, that’s why I am so insecure as to what causes it. there’s no lead at all.

this is what I see:

If we’re ever to get to the bottom of this, please make sure your logger is set up at least like this:

logger:
  default: info
  logs:
    homeassistant.core: debug

Then you won’t have to guess.

This is invalid:

      condition: template
      value_template: >
        {{states.script.intercom_text_message.context.user_id != None}}

Where in here does it say anything about a State Object having a context field?

I think you probably meant:

      condition: template
      value_template: >
        {{trigger.to_state.context.user_id != None}}

And generally it should be written this way:

      condition: template
      value_template: >
        {{trigger.to_state.context.user_id is not none}}

(And, yes, none should be all lower case because it’s not a value, it’s a test.)

dont know where I got that from…
if I were to write it with the actual triggering entity, how could one write that (that is, in this case the script.intercom_text_message? Or isnt that possible at all?

Does it make sense these errors now mostly appear when reloading the config? Ive yet to see them during regular operation
(restarted now with the correct logger settings, which btw already had script and automation and template helpers set to debug.)


so after restart, there’s no mentioning of the error. Forcing a manual reload results in this:

2020-08-01 23:44:37 ERROR (MainThread) [homeassistant.helpers.condition] Error during template condition: UndefinedError: 'None' has no attribute 'entity_id'
2020-08-01 23:44:37 ERROR (MainThread) [homeassistant.helpers.condition] Error during template condition: UndefinedError: 'None' has no attribute 'entity_id'
2020-08-01 23:44:37 ERROR (MainThread) [homeassistant.helpers.condition] Error during template condition: UndefinedError: 'None' has no attribute 'entity_id'
2020-08-01 23:44:37 ERROR (MainThread) [homeassistant.helpers.condition] Error during template condition: UndefinedError: 'None' has no attribute 'entity_id'
2020-08-01 23:44:37 ERROR (MainThread) [homeassistant.helpers.condition] Error during template condition: UndefinedError: 'None' has no attribute 'entity_id'
2020-08-01 23:44:37 ERROR (MainThread) [homeassistant.helpers.condition] Error during template condition: UndefinedError: 'None' has no attribute 'entity_id'
2020-08-01 23:44:37 ERROR (MainThread) [homeassistant.helpers.condition] Error during template condition: UndefinedError: 'None' has no attribute 'entity_id'
2020-08-01 23:44:38 ERROR (MainThread) [homeassistant.helpers.condition] Error during template condition: UndefinedError: 'None' has no attribute 'entity_id'
2020-08-01 23:44:39 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event system_log_event[L]: name=homeassistant.helpers.condition, message=["Error during template condition: UndefinedError: 'None' has no attribute 'entity_id'"], level=ERROR, source=['helpers/condition.py', 420], timestamp=1596318277.697244, exception=, count=1, first_occurred=1596318277.697244>
2020-08-01 23:44:39 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event system_log_event[L]: name=homeassistant.helpers.condition, message=["Error during template condition: UndefinedError: 'None' has no attribute 'entity_id'"], level=ERROR, source=['helpers/condition.py', 420], timestamp=1596318277.7075977, exception=, count=1, first_occurred=1596318277.7075977>
2020-08-01 23:44:39 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event system_log_event[L]: name=homeassistant.helpers.condition, message=["Error during template condition: UndefinedError: 'None' has no attribute 'entity_id'"], level=ERROR, source=['helpers/condition.py', 420], timestamp=1596318277.714817, exception=, count=1, first_occurred=1596318277.714817>
2020-08-01 23:44:39 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event system_log_event[L]: name=homeassistant.helpers.condition, message=["Error during template condition: UndefinedError: 'None' has no attribute 'entity_id'"], level=ERROR, source=['helpers/condition.py', 420], timestamp=1596318277.7193956, exception=, count=1, first_occurred=1596318277.7193956>
2020-08-01 23:44:39 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event system_log_event[L]: name=homeassistant.helpers.condition, message=["Error during template condition: UndefinedError: 'None' has no attribute 'entity_id'"], level=ERROR, source=['helpers/condition.py', 420], timestamp=1596318277.7223308, exception=, count=1, first_occurred=1596318277.7223308>
2020-08-01 23:44:39 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event system_log_event[L]: name=homeassistant.helpers.condition, message=["Error during template condition: UndefinedError: 'None' has no attribute 'entity_id'"], level=ERROR, source=['helpers/condition.py', 420], timestamp=1596318277.7252786, exception=, count=1, first_occurred=1596318277.7252786>
2020-08-01 23:44:39 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event system_log_event[L]: name=homeassistant.helpers.condition, message=["Error during template condition: UndefinedError: 'None' has no attribute 'entity_id'"], level=ERROR, source=['helpers/condition.py', 420], timestamp=1596318277.727718, exception=, count=1, first_occurred=1596318277.727718>
2020-08-01 23:44:39 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event system_log_event[L]: name=homeassistant.helpers.condition, message=["Error during template condition: UndefinedError: 'None' has no attribute 'entity_id'"], level=ERROR, source=['helpers/condition.py', 420], timestamp=1596318278.1770926, exception=, count=1, first_occurred=1596318278.1770926>
2020-08-01 23:44:40 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.2858477264] Sending {'id': 3763, 'type': 'event', 'event': {'event_type': 'system_log_event', 'data': {'name': 'homeassistant.helpers.condition', 'message': ["Error during template condition: UndefinedError: 'None' has no attribute 'entity_id'"], 'level': 'ERROR', 'source': ['helpers/condition.py', 420], 'timestamp': 1596318277.697244, 'exception': '', 'count': 1, 'first_occurred': 1596318277.697244}, 'origin': 'LOCAL', 'time_fired': datetime.datetime(2020, 8, 1, 21, 44, 39, 761772, tzinfo=<UTC>), 'context': {'id': '257cc4dd19fe4acfa649d824b676a55d', 'parent_id': None, 'user_id': None}}}
2020-08-01 23:44:40 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.2858477264] Sending {'id': 3763, 'type': 'event', 'event': {'event_type': 'system_log_event', 'data': {'name': 'homeassistant.helpers.condition', 'message': ["Error during template condition: UndefinedError: 'None' has no attribute 'entity_id'"], 'level': 'ERROR', 'source': ['helpers/condition.py', 420], 'timestamp': 1596318277.7075977, 'exception': '', 'count': 1, 'first_occurred': 1596318277.7075977}, 'origin': 'LOCAL', 'time_fired': datetime.datetime(2020, 8, 1, 21, 44, 39, 761994, tzinfo=<UTC>), 'context': {'id': 'f5a7a809ac7a43998a57f734df0386d8', 'parent_id': None, 'user_id': None}}}
2020-08-01 23:44:40 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.2858477264] Sending {'id': 3763, 'type': 'event', 'event': {'event_type': 'system_log_event', 'data': {'name': 'homeassistant.helpers.condition', 'message': ["Error during template condition: UndefinedError: 'None' has no attribute 'entity_id'"], 'level': 'ERROR', 'source': ['helpers/condition.py', 420], 'timestamp': 1596318277.714817, 'exception': '', 'count': 1, 'first_occurred': 1596318277.714817}, 'origin': 'LOCAL', 'time_fired': datetime.datetime(2020, 8, 1, 21, 44, 39, 766822, tzinfo=<UTC>), 'context': {'id': 'b52d9f0a43a141cb9b04272a43f3443c', 'parent_id': None, 'user_id': None}}}
2020-08-01 23:44:40 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.2858477264] Sending {'id': 3763, 'type': 'event', 'event': {'event_type': 'system_log_event', 'data': {'name': 'homeassistant.helpers.condition', 'message': ["Error during template condition: UndefinedError: 'None' has no attribute 'entity_id'"], 'level': 'ERROR', 'source': ['helpers/condition.py', 420], 'timestamp': 1596318277.7193956, 'exception': '', 'count': 1, 'first_occurred': 1596318277.7193956}, 'origin': 'LOCAL', 'time_fired': datetime.datetime(2020, 8, 1, 21, 44, 39, 767015, tzinfo=<UTC>), 'context': {'id': '28d86fd7db2b4670aec27fd42bdccb75', 'parent_id': None, 'user_id': None}}}
2020-08-01 23:44:40 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.2858477264] Sending {'id': 3763, 'type': 'event', 'event': {'event_type': 'system_log_event', 'data': {'name': 'homeassistant.helpers.condition', 'message': ["Error during template condition: UndefinedError: 'None' has no attribute 'entity_id'"], 'level': 'ERROR', 'source': ['helpers/condition.py', 420], 'timestamp': 1596318277.7223308, 'exception': '', 'count': 1, 'first_occurred': 1596318277.7223308}, 'origin': 'LOCAL', 'time_fired': datetime.datetime(2020, 8, 1, 21, 44, 39, 767909, tzinfo=<UTC>), 'context': {'id': '84d254fed0bb4565bdb3d66858fa927a', 'parent_id': None, 'user_id': None}}}
2020-08-01 23:44:40 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.2858477264] Sending {'id': 3763, 'type': 'event', 'event': {'event_type': 'system_log_event', 'data': {'name': 'homeassistant.helpers.condition', 'message': ["Error during template condition: UndefinedError: 'None' has no attribute 'entity_id'"], 'level': 'ERROR', 'source': ['helpers/condition.py', 420], 'timestamp': 1596318277.7252786, 'exception': '', 'count': 1, 'first_occurred': 1596318277.7252786}, 'origin': 'LOCAL', 'time_fired': datetime.datetime(2020, 8, 1, 21, 44, 39, 768099, tzinfo=<UTC>), 'context': {'id': '7b035fed29bb4f12a41e08fc2c40b51f', 'parent_id': None, 'user_id': None}}}
2020-08-01 23:44:40 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.2858477264] Sending {'id': 3763, 'type': 'event', 'event': {'event_type': 'system_log_event', 'data': {'name': 'homeassistant.helpers.condition', 'message': ["Error during template condition: UndefinedError: 'None' has no attribute 'entity_id'"], 'level': 'ERROR', 'source': ['helpers/condition.py', 420], 'timestamp': 1596318277.727718, 'exception': '', 'count': 1, 'first_occurred': 1596318277.727718}, 'origin': 'LOCAL', 'time_fired': datetime.datetime(2020, 8, 1, 21, 44, 39, 769735, tzinfo=<UTC>), 'context': {'id': 'aa1758cd35b148b29f95f17d9b75d4de', 'parent_id': None, 'user_id': None}}}
2020-08-01 23:44:40 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.2858477264] Sending {'id': 3763, 'type': 'event', 'event': {'event_type': 'system_log_event', 'data': {'name': 'homeassistant.helpers.condition', 'message': ["Error during template condition: UndefinedError: 'None' has no attribute 'entity_id'"], 'level': 'ERROR', 'source': ['helpers/condition.py', 420], 'timestamp': 1596318278.1770926, 'exception': '', 'count': 1, 'first_occurred': 1596318278.1770926}, 'origin': 'LOCAL', 'time_fired': datetime.datetime(2020, 8, 1, 21, 44, 39, 787487, tzinfo=<UTC>), 'context': {'id': '94dff6e7fc904a7495e12830fc5163da', 'parent_id': None, 'user_id': None}}}

if I search for the 'id': 3763 there are 2511 hits…

separate post: we’re on to something… searched the full log for the above again, and found this section:

2020-08-01 23:44:39 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=automation.send_notification_when_alarm_triggered, old_state=<state automation.send_notification_when_alarm_triggered=off; last_triggered=2020-02-14T09:03:30.538820+01:00, mode=single, friendly_name=Send notification when alarm triggered, templates=icon_color=if (state == 'on') return 'gold'; return 'steelblue';
, hide_attributes=['templates', 'editable', 'icon_color'] @ 2020-08-01T23:44:39.766231+02:00>, new_state=None>
2020-08-01 23:44:39 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event system_log_event[L]: name=homeassistant.helpers.condition, message=["Error during template condition: UndefinedError: 'None' has no attribute 'entity_id'"], level=ERROR, source=['helpers/condition.py', 420], timestamp=1596318277.714817, exception=, count=1, first_occurred=1596318277.714817>
2020-08-01 23:44:39 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event system_log_event[L]: name=homeassistant.helpers.condition, message=["Error during template condition: UndefinedError: 'None' has no attribute 'entity_id'"], level=ERROR, source=['helpers/condition.py', 420], timestamp=1596318277.7193956, exception=, count=1, first_occurred=1596318277.7193956>
2020-08-01 23:44:39 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=automation.send_notification_when_alarm_is_in_arming_status, old_state=<state automation.send_notification_when_alarm_is_in_arming_status=on; last_triggered=2020-06-10T12:41:33.990414+02:00, mode=single, friendly_name=Send notification when alarm is in arming status, templates=icon_color=if (state == 'on') return 'gold'; return 'steelblue';

which has 2 mentions, in between 2 other automations of my alarm_panel package. As it happens that has 1 (…) automation with a {{trigger.entity_id}} triggering on binary_sensors of my motion sensors. Here comes the thing:
those binaries still had their names from the former CC Hue sensors, in the form of

      entity_id:
        - binary_sensor.laundry_motion_sensor
        - binary_sensor.dining_table_motion_sensor
        - binary_sensor.auditorium_motion_sensor

while they now are part of the core Hue integration carrying entity_id’s like:

      entity_id:
        - binary_sensor.attic_sensor_motion
        - binary_sensor.auditorium_sensor_motion
        - binary_sensor.control_room_sensor_motion

so that figures…
reloading once more to see what gives…

A state object does not have context. A trigger does. Context is associated with something happening. So you’re asking about something that doesn’t exist.

That is too generic of a question. If you get an error then you have to determine what caused that error, no matter when it’s happening.

If an error is reported in the log, oftentimes the thing to do is to see what preceded it. Just posting the error isn’t useful by itself.

That has to do with HA communicating with the frontend. That is also not useful here. It’s just a domino that comes after the dominoes that fell before it.

That first state_changed event is probably just one very small part of the process of reloading. The automation is first removed, which causes its new state to become None. Notice: “new_state=None

Then you have a couple of system log events, which are, again, later dominoes.

Find the call_service message that indicates the beginning of the reload process. You should see a lot of state_changed events showing all the automations being removed from the system. Then there should be a bunch of “Initialized trigger AUTOMATION NAME” messages which are part of the process of adding the automations back in. There should also be a lot of state_changed events where old_state=None as well.

Somewhere after that call_service line find the first ERROR line that indicates the error we’ve been talking about. NOW, somewhere between call_service and that ERROR are useful lines that can help determine the cause of the error. Did an automation trigger? If so, which one? What was the state_changed or other type of event line that preceded the automation being trigger that is likely the cause of the trigger? Take that event information and look at the automation. Is the automation handling that event correctly?

You have to be more of a detective if you’re going to figure out what’s causing the error.

Thanks Phil, the hunting continues, albeit intensified with all this info. Will get back when necessary…

just to be sure, this is ok isnt it"

      - service: script.alarm_triggered
        data_template:
          entityid: >
            {{trigger.entity_id}}

for an automation with these triggers:

automation:
  - alias: Trigger alarm while armed
    trigger:
      platform: state
      entity_id:
        - binary_sensor.attic_sensor_motion
        - binary_sensor.auditorium_sensor_motion

not using a to: so I didnt try the trigger.to_state.entity_id

No, you want an underscore in entity_id, because that’s what the script is expecting.

Hi Marc, thanks,
sorry if I didnt specify clearly enough what the script does with the variable, which is:

  alarm_triggered:
    alias: Alarm triggered
    mode: queued
    sequence:
      - condition: state
        entity_id: input_boolean.notify_alarm
        state: 'on'
#      - condition: template
#        value_template: >
#          {{is_state('input_boolean.notify_alarm','on')}}
      - service: notify.mobile_app_calltheboss
        data_template:
          title: >
            {% set room = entityid.split('.')[1].split('_sensor_motion')[0].replace('_',' ')|capitalize %}
            Alarm triggered in the {{room}}
          message: >
            {% set name = entityid.split('.')[1].replace('_',' ')|capitalize %}
            {{as_timestamp(now())|timestamp_custom('%X')}}: {{name}} triggered the alarm, check whats up!

I always try to prevent using reserved names as variable, but stay as close to them as possible…

my question was in fact focused on the ‘{{trigger.entity_id}}’

Yes, that’s fine.

And trigger.to_state exists regardless of whether or not the trigger used the to option. (Same for from.) There’s still a change of state, so there’s still a from_state and a to_state. The to option is simply limiting which of those state changes will cause the trigger to fire.

still havent found it… yet, another side question. Triggering an automation in my setup shows this in the log:

2020-08-03 12:27:20 INFO (MainThread) [homeassistant.components.automation] Update Rss feed sensors: Running script
2020-08-03 12:27:20 INFO (MainThread) [homeassistant.components.automation] Update Rss feed sensors: Executing step call service
2020-08-03 12:27:20 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.2844917496] Sending {'id': 4084, 'type': 'event', 'event': {'event_type': 'system_log_event', 'data': {'name': 'homeassistant.helpers.condition', 'message': ["Error during template condition: UndefinedError: 'None' has no attribute 'entity_id'"], 'level': 'ERROR', 'source': ['helpers/condition.py', 420], 'timestamp': 1596450440.7942271, 'exception': '', 'count': 1, 'first_occurred': 1596450440.7942271}, 'origin': 'LOCAL', 'time_fired': datetime.datetime(2020, 8, 3, 10, 27, 20, 810373, tzinfo=<UTC>), 'context': {'id': '5b15f5f01edb49359b80cb85c5d8ffe3', 'parent_id': None, 'user_id': None}}}
2020-08-03 12:27:20 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.2838519256] Received {'type': 'persistent_notification/get', 'id': 36}

while the automation doesnt contain any script:

  - alias: Update Rss feed sensors
    trigger:
      - platform: event
        event_type: feedreader
      - platform: event
        event_type: call_service
        event_data:
          domain: persistent_notification
          service: dismiss
    mode: queued
    action:
      service: homeassistant.update_entity
      entity_id:
        - binary_sensor.rss_feeds
        - sensor.persistent_notifications

is that correct for the logger to show the line:

Update Rss feed sensors: Running script

?

I specifically ask about this automation, because I just received several errors around the time this automation is logged as you can see.

Yes, the action part of an automation is a script.

well, yes, of course I knew that. hadn’t realized it is being logged like that. sorry.

I am still completely lost why this keeps popping up. thing is the ERROR only shows with the given text, while I need to find a service which doesn’t show an error…

this is the hard bit. especially since the log is huuuge. And all in between lines are fine so far, or show autoamtions/scripts without entity_id in the template ;-)(

it would be of enormous help if this:

would list the actual template and or script/automation that generates it.

again, some progress and please let repost here for feedback, because it doesnt really comply with the error… it does with an incorrect entity_id

had this sensor:

      count_hubs_offline:
        friendly_name: Hubs offline
        entity_id:
          - binary_sensor.asus_router
          - binary_sensor.hassio_mqtt
          - binary_sensor.hassio_rpi4
          - binary_sensor.ikea_tradfri
 #         - binary_sensor.philips_hue  # previously listed
          - binary_sensor.philips_hue_1
          - binary_sensor.philips_hue_2
          - binary_sensor.iungo
          - binary_sensor.solaredge
          - binary_sensor.timecapsule
          - binary_sensor.synology
          - binary_sensor.kantoor_thermostat
        value_template: >
          {% set offline = expand('group.hubs_binary_pinged')
           |selectattr('state','eq','off')|list|count %}
          {{offline}}

which had in incorrect (old) entity_id listed, a remnant of my earlier config, when I still had 1 Hue hub :wink:

the group in the template is correct, and does hold the correct entity_id’s, so wonder if this could be an issue. (it is at least odd the conf checker doesnt check for correct/existing entity_id’s)

a more serious error probably was in another sensor:

      count_critical_devices_offline:
        friendly_name: Critical devices offline
        entity_id:
          - sensor.cv_garage_state
          - sensor.cv_stookhok_state
          - sensor.cv_zolder_state
          - sensor.zonneboiler_zolder_state
          - sensor.freezer_bijkeuken_state
        value_template: >
          {% set offline = expand('group.critical_devices')
           |selectattr('state','eq','off')|list|count %}
          {{offline}}

where the group was wrong (again, a remnant of an earlier config) and stated expand('group.critical_devices_state')

this now should errored too of course, and maybe even more than the one above.

since these 2 are part of a larger set of alerts (and automations concerning these alerts) this might have caused havoc.

Phil, could this somehow have led to the error I am trying to hunt down? Without actually being in an automation or script?