Error in log for automation, but yaml is valid

I have this error message in the sys-log:

with this details:

Logger: homeassistant.components.automation.shelly_button
Source: core.py:1405
Integration: Automation (documentation, issues)
First occurred: 4:53:11 (2 occurrences)
Last logged: 21:46:54

While executing automation automation.shelly_button

Traceback (most recent call last): File “/usr/src/homeassistant/homeassistant/components/automation/init.py”, line 433, in async_trigger await self.action_script.async_run( File “/usr/src/homeassistant/homeassistant/helpers/script.py”, line 1010, in async_run await asyncio.shield(run.async_run()) File “/usr/src/homeassistant/homeassistant/helpers/script.py”, line 245, in async_run await self._async_step(log_exceptions=False) File “/usr/src/homeassistant/homeassistant/helpers/script.py”, line 253, in _async_step await getattr( File “/usr/src/homeassistant/homeassistant/helpers/script.py”, line 463, in _async_call_service_step await self._async_run_long_action(service_task) File “/usr/src/homeassistant/homeassistant/helpers/script.py”, line 422, in _async_run_long_action long_task.result() File “/usr/src/homeassistant/homeassistant/core.py”, line 1405, in async_call processed_data = handler.schema(service_data) File “/usr/local/lib/python3.8/site-packages/voluptuous/validators.py”, line 218, in call return self._exec((Schema(val) for val in self.validators), v) File “/usr/local/lib/python3.8/site-packages/voluptuous/validators.py”, line 340, in _exec raise e if self.msg is None else AllInvalid(self.msg, path=path) File “/usr/local/lib/python3.8/site-packages/voluptuous/validators.py”, line 336, in _exec v = func(v) File “/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py”, line 272, in call return self._compiled(, data) File “/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py”, line 817, in validate_callable return schema(data) File “/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py”, line 272, in call return self._compiled(, data) File “/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py”, line 594, in validate_dict return base_validate(path, iteritems(data), out) File “/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py”, line 432, in validate_mapping raise er.MultipleInvalid(errors) voluptuous.error.MultipleInvalid: not a valid value for dictionary value @ data[‘entity_id’]

Logger: homeassistant.components.automation.shelly_button
Source: helpers/script.py:1122
Integration: Automation (documentation, issues)
First occurred: 4:53:11 (2 occurrences)
Last logged: 21:46:54

Shelly Button: Error executing script. Invalid data for call_service at pos 1: not a valid value for dictionary value @ data[‘entity_id’]

but yaml-configuration ist checked as valid.

This is the code of the script:

  alias: Shelly Button
  description: Aktion ausführen entsprechend Klicks auf Shelly Button
  trigger:
  - platform: mqtt
    topic: shellies/shellybutton1-D8F15B154F21/input_event/0
  condition: []
  action:
  - service: script.turn_on
    data_template:
      entity_id: >
        {% if trigger.payload_json.event == "S" %}
          script.kurz1
        {% elif trigger.payload_json.event == "SS" %}
          script.kurz2
        {% elif trigger.payload_json.event == "SSS" %}
          script.kurz3
        {% elif trigger.payload_json.event == "L" %}
          script.lang
        {% endif %}
  mode: single

And the automation works as excpected…

Any hint why I get an error in the log? :woozy_face:

I suspect that you’re getting payloads that don’t match any of the ones you have in your if statements, and because you have no catch-all ‘else’ when that happens your template doesn’t resolve to an entity_id, hence the error.

4 Likes

Thanks for quick reply :smiley:

Button can only send these four payloads: S, SS, SSS and L
S = single click
SS = double click
SSS = tripple click
L = long click

So I guess it should be another reason, but I will expand the code for unkwon payloads so I will see if these is the problem.

I agree with @anon43302295. Only issue I see is if the state is different from what you have programmed

2 Likes

Try posting the results to a persistent notification

1 Like

I will try :slight_smile:

As am still a beginner with HA and Yaml, is this correct?

  alias: Shelly Button
  description: Aktion ausführen entsprechend Klicks auf Shelly Button
  trigger:
  - platform: mqtt
    topic: shellies/shellybutton1-D8F15B154F21/input_event/0
  condition: []
  action:
  - service: script.turn_on
    data_template:
      entity_id: >
        {% if trigger.payload_json.event == "S" %}
          script.kurz1
        {% elif trigger.payload_json.event == "SS" %}
          script.kurz2
        {% elif trigger.payload_json.event == "SSS" %}
          script.kurz3
        {% elif trigger.payload_json.event == "L" %}
          script.lang
        {% else %}
          service: persistent_notification.create
          data:
          message: trigger.payload_json.event
          title: "Shelly Button Unknown Payload"
        {% endif %}
  mode: single

No.

Your else case resolves to:

  - service: script.turn_on
    data_template:
      entity_id: service: persistent_notification.create
        data:
        message: trigger.payload_json.event
        title: "Shelly Button Unknown Payload"

Put this in a script (note the corrected data indentation):

          service: persistent_notification.create
          data:
            message: "{{ trigger.payload_json.event }}"
            title: "Shelly Button Unknown Payload"

And include the script entity id in your {% else %} case.

Also note that data_template has been depreciated since 0.115. Just use data.

:open_mouth: is the value of trigger.payload_json.event in a seperate script still available and known?

No it isn’t. Sorry. Hang on…

Try this (scripts are services):

  action:
  - service: >
        {% if trigger.payload_json.event == "S" %}
          script.kurz1
        {% elif trigger.payload_json.event == "SS" %}
          script.kurz2
        {% elif trigger.payload_json.event == "SSS" %}
          script.kurz3
        {% elif trigger.payload_json.event == "L" %}
          script.lang
        {% else %}
          persistent_notification.create
          data:
            message: "{{ trigger.payload_json.event }}"
            title: "Shelly Button Unknown Payload"
        {% endif %}
  mode: single

I’m not sure about including the data in the service. Try it and see.

Thanks, unfortunately it didnt’t work.

I do it right now this way:

  alias: Shelly Button
  description: Aktion ausführen entsprechend Klicks auf Shelly Button
  trigger:
  - platform: mqtt
    topic: shellies/shellybutton1-D8F15B154F21/input_event/0
  condition: []
  action:
  - service: persistent_notification.create
    data:
      message: "{{ trigger.payload_json.event }}"
      title: "Shelly Button Unknown Payload"
  - service: script.turn_on
    data_template:
      entity_id: >
        {% if trigger.payload_json.event == "S" %}
          script.kurz1
        {% elif trigger.payload_json.event == "SS" %}
          script.kurz2
        {% elif trigger.payload_json.event == "SSS" %}
          script.kurz3
        {% elif trigger.payload_json.event == "L" %}
          script.lang
        {% else %}
        {% endif %}
  mode: single

So I get alway a notification, as long as I dont press the button I should get only the unkown payload.
By pressing the button I get always (multiple tests) and only the known payloads (S, SS, SSS, L).

What version of home assistant are you running?

I have Version 0.118.2
HassOS is running on 4.17

This night the “unkown” palyload has triggerd :slight_smile: and I get the log-error once again (I removed the {% else % } statment in the automation before :wink:)

log-error:

And this ist what I get in the notificatios:
image

So it seems that the Shelly button sends without action from a user somtimes an empty (?) payload.

So I will add the {% else % } statement in the automation with no action an the error should not longer be seen in the log.

Tanks for all your help!
:relaxed: