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

Not odd at all. And you wouldn’t want it to do that, because many entities are created dynamically. There would be no way for a static config checker to know what entities will or won’t exist at run time.

Anything is possible I guess. But guessing doesn’t help, as we’ve discussed before. :wink:

FWIW, I believe using the expand() function in a template can now allow the template sensor/trigger to automatically determine the entities to watch, so it may no longer be required to use the entity_id option. However, I’m not 100% sure that works in all cases, so ymmv.

I recommend you search your configuration for trigger.entity_id, trigger.to_state.entity_id and trigger.from_state.entity_id. Make sure you search all your files. This will help you identify the automation in question.

believe me, I have been following both of your advises. searched thousands of lines of logs, and still didnt find a clue.

This morning, all of a sudden I got 14 GitHub repo updates of my GitHub package (mostly an error when this occurs after a GitHub connection outage or so) .And, more importantly, I saw logs with a clue finally:

Logger: homeassistant.components.automation
Source: helpers/service.py:135 
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: 8:43:30 AM (34 occurrences) 
Last logged: 9:45:32 AM

* GitHub repo update: Error executing script. Unexpected error for call_service at pos 3: Error rendering data template: UndefinedError: 'None' has no attribute 'split'
* While executing automation automation.github_repo_update

below is the automation:

  - alias: GitHub repo update
    trigger:
      platform: event
      event_type: state_changed
    condition:
      - condition: template
        value_template: >
          {{trigger.event.data.entity_id.startswith('sensor.github')}}
      - condition: template
        value_template: >
          {{'old_state' in trigger.event.data and 'new_state' in trigger.event.data and
            trigger.event.data.new_state.attributes.latest_release_url !=
            trigger.event.data.old_state.attributes.latest_release_url}}
    action:
      - service: input_boolean.turn_on
        data_template:
          entity_id: >
            input_boolean.{{trigger.event.data.new_state.object_id}}
      - service: input_boolean.turn_on
        entity_id: input_boolean.github_repo_update

      - service: script.notify_github
        data_template:
          repo: >
            {{state_attr(trigger.event.data.entity_id,'name')}}
          url: >
            {{state_attr(trigger.event.data.entity_id,'latest_release_url')}}
          tag: >
            {{state_attr(trigger.event.data.entity_id,'latest_release_url').split('tag/')[1]}}
          object: >
            {{trigger.event.data.entity_id.split('.')[1]}}

so this errors on the last service, more specifically the lines with the .split.

It still confuses me why it says 'None' has no attribute 'split', because I don’t template an attribute ‘split’ at all. Moreover, if it complains about ‘None’ why not in the 2 before that (repo and url) ?

question now is how to guard this. I might be safest adding a full automation condition template like this:

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

making this the ‘Condition template Shield that guards the realms of automations’

Would this be a valid condition on the event state_changed trigger? I already check on the existence of old_state and new_state.

["Error during template condition: UndefinedError: 'dict object' has no attribute 'to_state'"],


Guess not :wink:

would this help then:

      - condition: template
        value_template: >
          {{trigger.event.data.entity_id is not none and
            'old_state' in trigger.event.data and 'new_state' in trigger.event.data and
            trigger.event.data.new_state != trigger.event.data.old_state}}

Feels rather superfluous since I already have some conditional tests .

Or, should I guard the individual templates in the 3d service call?

second positive conclusion: I see the error on each persistent notification dismissal. Haven’t found the templated ‘entity_id’ in any related automation/script/template sensor yet, but this needs further investigation. Will click dismiss one more and find the last few seconds in the log…

this is a log section, occurring after dismissal of a persistent_notification.

would you please look with me for possible issues?

2020-08-05 13:06:54 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: domain=persistent_notification, service=dismiss, service_data=notification_id=github_light_entity>
2020-08-05 13:06:54 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=persistent_notification.github_light_entity, old_state=<state persistent_notification.github_light_entity=notifying; title=Github update for Light entity, message=![image](/local/various/github_icon.png) Light entity was updated to 4.2.0. Download the [latest release](https://github.com/ljmerza/light-entity-card/releases/tag/4.2.0) @ 2020-08-05T09:44:37.423980+02:00>, new_state=None>
2020-08-05 13:06:54 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event persistent_notifications_updated[L]>
2020-08-05 13:06:54 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.2848559936] Sending {'id': 4185, 'type': 'event', 'event': {'event_type': 'call_service', 'data': {'domain': 'persistent_notification', 'service': 'dismiss', 'service_data': {'notification_id': 'github_light_entity'}}, 'origin': 'LOCAL', 'time_fired': datetime.datetime(2020, 8, 5, 11, 6, 54, 526156, tzinfo=<UTC>), 'context': {'id': '65f7fe119b3b4deaacb28fdd7bea4cbe', 'parent_id': None, 'user_id': '3a8d4c2a87334e2a96b7822f67356b63'}}}
2020-08-05 13:06:54 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=automation.update_rss_feed_sensors, old_state=<state automation.update_rss_feed_sensors=on; last_triggered=2020-08-05T13:04:40.935287+02:00, mode=queued, max=10, current=1, friendly_name=Update Rss feed sensors, templates=icon_color=if (state == 'on') return 'gold'; return 'steelblue';
, hide_attributes=['templates', 'editable', 'icon_color'] @ 2020-08-05T13:02:41.527035+02:00>, new_state=
, hide_attributes=['templates', 'editable', 'icon_color'] @ 2020-08-05T13:02:41.527035+02:00>>
2020-08-05 13:06:54 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event automation_triggered[L]: name=Update Rss feed sensors, entity_id=automation.update_rss_feed_sensors>
2020-08-05 13:06:54 INFO (MainThread) [homeassistant.components.automation] Executing Update Rss feed sensors
2020-08-05 13:06:54 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=automation.github_persistent_notification_dismissal_turns_off_boolean, old_state=<state automation.github_persistent_notification_dismissal_turns_off_boolean=on; last_triggered=2020-08-05T13:04:40.936706+02:00, mode=restart, friendly_name=Github persistent notification dismissal turns off boolean, templates=icon_color=if (state == 'on') return 'gold'; return 'steelblue';
, hide_attributes=['templates', 'editable', 'icon_color'] @ 2020-08-05T13:02:41.531772+02:00>, new_state=
, hide_attributes=['templates', 'editable', 'icon_color'] @ 2020-08-05T13:02:41.531772+02:00>>
2020-08-05 13:06:54 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event automation_triggered[L]: name=Github persistent notification dismissal turns off boolean, entity_id=automation.github_persistent_notification_dismissal_turns_off_boolean>
2020-08-05 13:06:54 INFO (MainThread) [homeassistant.components.automation] Executing Github persistent notification dismissal turns off boolean
2020-08-05 13:06:54 INFO (MainThread) [homeassistant.components.automation] Github persistent notification dismissal turns off boolean: Running script
2020-08-05 13:06:54 INFO (MainThread) [homeassistant.components.automation] Github persistent notification dismissal turns off boolean: Executing step call service
2020-08-05 13:06:54 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.2848559936] Sending {'id': 4185, 'type': 'event', 'event': {'event_type': 'state_changed', 'data': {'entity_id': 'persistent_notification.github_light_entity', 'old_state': <state persistent_notification.github_light_entity=notifying; title=Github update for Light entity, message=![image](/local/various/github_icon.png) Light entity was updated to 4.2.0. Download the [latest release](https://github.com/ljmerza/light-entity-card/releases/tag/4.2.0) @ 2020-08-05T09:44:37.423980+02:00>, 'new_state': None}, 'origin': 'LOCAL', 'time_fired': datetime.datetime(2020, 8, 5, 11, 6, 54, 527296, tzinfo=<UTC>), 'context': {'id': '65f7fe119b3b4deaacb28fdd7bea4cbe', 'parent_id': None, 'user_id': '3a8d4c2a87334e2a96b7822f67356b63'}}}
2020-08-05 13:06:54 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.2848559936] Sending {'id': 4185, 'type': 'event', 'event': {'event_type': 'persistent_notifications_updated', 'data': {}, 'origin': 'LOCAL', 'time_fired': datetime.datetime(2020, 8, 5, 11, 6, 54, 527719, tzinfo=<UTC>), 'context': {'id': '32ce051a89f84fe5b8836e9d00d04358', 'parent_id': None, 'user_id': None}}}
2020-08-05 13:06:54 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.2848559936] Sending {'id': 4185, 'type': 'event', 'event': {'event_type': 'state_changed', 'data': {'entity_id': 'automation.update_rss_feed_sensors', 'old_state': <state automation.update_rss_feed_sensors=on; last_triggered=2020-08-05T13:04:40.935287+02:00, mode=queued, max=10, current=1, friendly_name=Update Rss feed sensors, templates=icon_color=if (state == 'on') return 'gold'; return 'steelblue';
, hide_attributes=['templates', 'editable', 'icon_color'] @ 2020-08-05T13:02:41.527035+02:00>, 'new_state': 
, hide_attributes=['templates', 'editable', 'icon_color'] @ 2020-08-05T13:02:41.527035+02:00>}, 'origin': 'LOCAL', 'time_fired': datetime.datetime(2020, 8, 5, 11, 6, 54, 532714, tzinfo=), 'context': {'id': 'da9a7369e33244c387ed5b482e5b7917', 'parent_id': '65f7fe119b3b4deaacb28fdd7bea4cbe', 'user_id': None}}}
2020-08-05 13:06:54 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.2848559936] Sending {'id': 4185, 'type': 'event', 'event': {'event_type': 'automation_triggered', 'data': {'name': 'Update Rss feed sensors', 'entity_id': 'automation.update_rss_feed_sensors'}, 'origin': 'LOCAL', 'time_fired': datetime.datetime(2020, 8, 5, 11, 6, 54, 533197, tzinfo=<UTC>), 'context': {'id': 'da9a7369e33244c387ed5b482e5b7917', 'parent_id': '65f7fe119b3b4deaacb28fdd7bea4cbe', 'user_id': None}}}
2020-08-05 13:06:54 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.2848559936] Sending {'id': 4185, 'type': 'event', 'event': {'event_type': 'state_changed', 'data': {'entity_id': 'automation.github_persistent_notification_dismissal_turns_off_boolean', 'old_state': <state automation.github_persistent_notification_dismissal_turns_off_boolean=on; last_triggered=2020-08-05T13:04:40.936706+02:00, mode=restart, friendly_name=Github persistent notification dismissal turns off boolean, templates=icon_color=if (state == 'on') return 'gold'; return 'steelblue';
, hide_attributes=['templates', 'editable', 'icon_color'] @ 2020-08-05T13:02:41.531772+02:00>, 'new_state': 
, hide_attributes=['templates', 'editable', 'icon_color'] @ 2020-08-05T13:02:41.531772+02:00>}, 'origin': 'LOCAL', 'time_fired': datetime.datetime(2020, 8, 5, 11, 6, 54, 535506, tzinfo=), 'context': {'id': '752c5140a75d476a88924f8c7e0416c7', 'parent_id': '65f7fe119b3b4deaacb28fdd7bea4cbe', 'user_id': None}}}
2020-08-05 13:06:54 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.2848559936] Sending {'id': 4185, 'type': 'event', 'event': {'event_type': 'automation_triggered', 'data': {'name': 'Github persistent notification dismissal turns off boolean', 'entity_id': 'automation.github_persistent_notification_dismissal_turns_off_boolean'}, 'origin': 'LOCAL', 'time_fired': datetime.datetime(2020, 8, 5, 11, 6, 54, 535929, tzinfo=<UTC>), 'context': {'id': '752c5140a75d476a88924f8c7e0416c7', 'parent_id': '65f7fe119b3b4deaacb28fdd7bea4cbe', 'user_id': None}}}
2020-08-05 13:06:54 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.2785242608] Sending {'id': 2, 'type': 'event', 'event': <Event state_changed[L]: entity_id=persistent_notification.github_light_entity, old_state=<state persistent_notification.github_light_entity=notifying; title=Github update for Light entity, message=![image](/local/various/github_icon.png) Light entity was updated to 4.2.0. Download the [latest release](https://github.com/ljmerza/light-entity-card/releases/tag/4.2.0) @ 2020-08-05T09:44:37.423980+02:00>, new_state=None>}
2020-08-05 13:06:54 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.2785242608] Sending {'id': 25, 'type': 'event', 'event': {'event_type': 'persistent_notifications_updated', 'data': {}, 'origin': 'LOCAL', 'time_fired': datetime.datetime(2020, 8, 5, 11, 6, 54, 527719, tzinfo=<UTC>), 'context': {'id': '32ce051a89f84fe5b8836e9d00d04358', 'parent_id': None, 'user_id': None}}}
2020-08-05 13:06:54 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.2785242608] Sending {'id': 2, 'type': 'event', 'event': <Event state_changed[L]: entity_id=automation.update_rss_feed_sensors, old_state=<state automation.update_rss_feed_sensors=on; last_triggered=2020-08-05T13:04:40.935287+02:00, mode=queued, max=10, current=1, friendly_name=Update Rss feed sensors, templates=icon_color=if (state == 'on') return 'gold'; return 'steelblue';
, hide_attributes=['templates', 'editable', 'icon_color'] @ 2020-08-05T13:02:41.527035+02:00>, new_state=
, hide_attributes=['templates', 'editable', 'icon_color'] @ 2020-08-05T13:02:41.527035+02:00>>}
2020-08-05 13:06:54 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.2785242608] Sending {'id': 2, 'type': 'event', 'event': <Event state_changed[L]: entity_id=automation.github_persistent_notification_dismissal_turns_off_boolean, old_state=<state automation.github_persistent_notification_dismissal_turns_off_boolean=on; last_triggered=2020-08-05T13:04:40.936706+02:00, mode=restart, friendly_name=Github persistent notification dismissal turns off boolean, templates=icon_color=if (state == 'on') return 'gold'; return 'steelblue';
, hide_attributes=['templates', 'editable', 'icon_color'] @ 2020-08-05T13:02:41.531772+02:00>, new_state=
, hide_attributes=['templates', 'editable', 'icon_color'] @ 2020-08-05T13:02:41.531772+02:00>>}
2020-08-05 13:06:54 ERROR (MainThread) [homeassistant.helpers.condition] Error during template condition: UndefinedError: 'None' has no attribute 'entity_id'
2020-08-05 13:06:54 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: domain=input_boolean, service=turn_off, service_data=entity_id=input_boolean.github_light_entity>
2020-08-05 13:06:54 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=1596625614.6127067, exception=, count=1, first_occurred=1596625614.6127067>
2020-08-05 13:06:54 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.2785242608] Sending {'id': 85, 'type': 'result', 'success': True, 'result': {'context': Context(user_id='3a8d4c2a87334e2a96b7822f67356b63', parent_id=None, id='67602e7bba6a409e8b0520ca0de96a8f')}}
2020-08-05 13:06:54 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.2785242608] Received {'type': 'persistent_notification/get', 'id': 86}
2020-08-05 13:06:54 INFO (MainThread) [homeassistant.components.automation] Update Rss feed sensors: Running script
2020-08-05 13:06:54 INFO (MainThread) [homeassistant.components.automation] Update Rss feed sensors: Executing step call service
2020-08-05 13:06:54 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.2848559936] Sending {'id': 4185, 'type': 'event', 'event': {'event_type': 'call_service', 'data': {'domain': 'input_boolean', 'service': 'turn_off', 'service_data': {'entity_id': 'input_boolean.github_light_entity'}}, 'origin': 'LOCAL', 'time_fired': datetime.datetime(2020, 8, 5, 11, 6, 54, 638192, tzinfo=<UTC>), 'context': {'id': '752c5140a75d476a88924f8c7e0416c7', 'parent_id': '65f7fe119b3b4deaacb28fdd7bea4cbe', 'user_id': None}}}
2020-08-05 13:06:54 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.2848559936] Sending {'id': 4185, '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': 1596625614.6127067, 'exception': '', 'count': 1, 'first_occurred': 1596625614.6127067}, 'origin': 'LOCAL', 'time_fired': datetime.datetime(2020, 8, 5, 11, 6, 54, 638803, tzinfo=<UTC>), 'context': {'id': '8f09573b9bfa49d4890178f2f808bfb0', 'parent_id': None, 'user_id': None}}}

Are you using a software that searches for you? Notepad++, visual studio code, etc? You can have these softwares search for the lines of code inside your entire configuration. That’s what you should be doing.

What are you trying to do with this? For a state_changed event, those keys will always be present. That isn’t doing anything. Now, their values could be None, so you should probably be checking for that:

trigger.event.data.old_state is not none and trigger.event.new_state is not none

In the condition you use this:

trigger.event.data.new_state.attributes.latest_release_url

but in the action you use this:

state_attr(trigger.event.data.entity_id,'latest_release_url')

You should be more consistent.

No, but you’re trying to use a string’s split() method, but apparently you don’t have a string, you have None.

My guess is the error is from this line:

{{state_attr(trigger.event.data.entity_id,'latest_release_url').split('tag/')[1]}}

The state_attr() function seems to be returning None.

Because those just return None, they don’t try to use a method of None that doesn’t exist.

See the first part of my reply.

It sounds like your system is chock full of problems. And I suspect many have existed for a while and maybe you were just really lucky.

If I were you I’d start with a fresh install and add things in one by one, checking them out thoroughly; both looking them over with everything you now know, and testing them as thoroughly as possible.

At this rate you’re never going to get to a completely reliable system.

But that’s just my 2 cents.

1 Like

sorry to dig up an old post, but because of this really, and it has never failed so I never changed that since…

but, with all you’ve told me now, I will change to your new suggestion forthwith.

point taken. trying to.
on this particular template:

{{state_attr(trigger.event.data.new_state, 'latest_release_url') !=
            state_attr(trigger.event.data.old_state,'latest_release_url')}}

hmm, you make it sound awful… its not that bad. I have these errors I am trying to get rid of, and that’s really it. Apart from one other repeating error

which is reported frequently here and on the GitHub. Still, I am taking your advice to heart, and am trying to re-build as methodically as possible.

yes I have, and that is not the big issue, it’s finding the right passages in the logs that’s difficult, since I cant use a search for what I dont know, and have to walk through as Phil described above.

that’s why I posted he snippet of the log and would hope to find a lead there.

“Jul '18” Really?! :roll_eyes:

That’s invalid.

My point is I know you have a very complex system that has been built, enhanced, modified, etc. over a long period of time, and through many, many HA releases. There’s every chance that there are multiple mistakes, some of which haven’t really manifested themselves in the past. When you have a system like this (which most of us do that have been using HA for any length of time), and you’re having problems that are difficult to diagnose and solve, it may be easier to go through everything with a fine toothed comb, so to speak, by starting fresh and adding things back in slowly, closely inspecting them and testing them as you go, rather than try to search for what seems to be a needle in a hay stack.

But then I tend to be a pessimist when it comes to this sort of thing, so…

I’m not sure how much more help I can be with this. It’s very difficult to look at these details out of context and have anything very useful to say/suggest.

now I am confused. I believed that was what you told me to do here:

or is it the incorrect use of ‘new_state’ in that template, which should really be ‘entity_id’? but how then to compare the old_state with the new_state…

yes, why are you not in agreement here anymore? what you wrote back then still seems very valid?

update:

after adding:

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

to 2 automations I have, which both trigger on a set of binary_sensors, and both use the {{trigger.entity_id}} I now seem to have lost the error upon reloading of the automations and scripts. Binary triggers apparently need extra care in the config.

Checked it couple of times, and all is green or grey, no more red lines in the Log viewer concerning the 'None' has no attribute 'entity_id'

There’s 1 left concerning the context, and that is something of a miracle, since it is already guarded:

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

odd thing about this, is this only shows up when reloading scripts, and not while reloading automations…

state_attr(trigger.event.data.new_state, 'latest_release_url')

What type do you think trigger.event.data.new_state is? I’ll give you a hint: it’s a State Object.

What is the first parameter to state_attr() supposed to be? I’ll give you a hint: an entity_id.

Is a State Object an entity_id?

You really need to think about what you’re doing and stop just copying & pasting. If you had thought about that for half a second you could have answered your own question, or not had a question in the first place.

Really? After everything you’ve done you can’t answer that question yourself? Please think about it. What type are old_state & new_state?

Do you think it’s just possible that two years ago, when I had just started using HA, that I might not have understood it as well as I do now, and that I might not have provided the best possible answer back then? :man_facepalming:

What do you think would happen if trigger.to_state was None?

well of course I would believe that to be possible. And please forgive me, but I was not trying to bug you. It was an honest question, on a template that still works very fine, and you now seem to have abandoned as a perfect solution to the issue at hand.

well, there wouldn’t be a context, nor a user_id either. you seem to have lost me, because I did follow your instructions at the beginning of this topic, and I get the feeling you are now telling me I am on the wrong track? I did btw add the test for {{trigger.to_state is not none}} but that doesn’t make a difference.

No, sorry, no matter how much you want to hold onto it, it was a bad suggestion in the first place. And I even stated at the time I had not tested it. You might want to check again. :smile:

Correct. And if you accessed trigger.to_state.context anyway that would cause an error.

That’s the problem with constantly posting snippets. There’s no way I can keep track of everything you’ve said in a topic that contains 30+ posts, most of which are little bits and pieces. When you post one condition out of context there’s no way for me to know (or remember) that that came after some other condition.

Honestly I can’t tell anymore. There are too many little bits of detail that I no longer have any idea what you have or what you’re trying to do. My basic suggestion is to work through the details. I believe you have a very complex system and it’s really hard to look at one tiny little piece and say, “yes, that’s the reason some error seems to be popping up randomly.”

Please don’t get me wrong. I don’t mind helping in general, but this one is just too complex to address this way. You’ve been given suggestions that can help you better see what is happening in your system. I’m not sure there’s much else I can do at this point.

right, you’re right, this has become somewhat convoluted. Please allow me one last thing then on the final issue at hand. I’ll post the fill automation for overview’s sake again, which now seems to be working, because I split the conditions, and added the context.user_id condition to the action block. This will then only be checked if trigger.to_state itself is None :

  - 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: >
        {{trigger.to_state is not none}}
    action:
      - condition: template
        value_template: >
          {{trigger.to_state.context.user_id is not none}}
      - 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}}

hope you agree this to be correct?

Yes, that looks like it should work. But why not combine both conditions into one?

I.e., change this:

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

into this:

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

yes, I had tried that before, and the error still showed. that’s why I split them as I explained above. Of course, that makes no sense. Can’t explain why that happened, because I have now retried that exact template, as you suggest, and all is well.
so, yes, thanks for that suggestion :wink:

only thing left is a more global question: how can it be explained the error on the context.user_id only shows when reloading scripts, and not automations?

forgot to answer Petro here, sorry for that, I am using Bbedit formerly known as Textwrangler.