Payload type not accepted in configuration.yaml. Error: No matching payload found for entity

This line generate wrong messages.
I had to change the last line with only:

{{ actions[trigger.to_state.state] }}

but error Error while executing automation automation.rileva_vibration. Invalid data for call_service at pos 1: required key not provided @ data[‘message’] is still there
Thank you very much for your help.

What do you mean by ‘wrong messages’?

If you only have this on the last line:

{{ actions[trigger.to_state.state] }}

then if trigger.to_state.state is NOT found in the actions dictionary, you will get an error message.

Change it to this which simply reports whatever value is received. This should not generate any error messages. If it does, then there’s something else causing it.

  action:
    service: notify.telegram
    data_template:
      message: 'State is ( {{ trigger.to_state.state }} )'

With your last line always generates a third empty event ( ) ’
It is also true that the error Error while executing automation automation.rileva_vibration. Invalid data for call_service at pos 1: required key not provided @ data[‘message’] is no longer generated

Then it confirms what I said earlier:

Your automation calls the Telegram service and sets message to trigger.to_state.state. However, if sensor.vibro contains no state (it is blank) then message is assigned a blank value which is invalid and you get the error: required key not provided @ data[‘message’].

According to the documentation for the Xiaomi DJT11LM, it has three states:

  • drop
  • tilt
  • touch

:man_shrugging:

At this point, I need to get a message whenever one of the three events goes wild.
So, how can I prevent the empty (blank) message will be generated and not having the error required key not provided @ data[‘message’]?

Try this:

- alias: 'Example2'
  trigger:
    platform: state
    entity_id: sensor.vibro
  condition:
    condition: template
    value_template: "{{ trigger.to_state.state | length > 0 }}"
  action:
    service: notify.telegram
    data_template:
      message: >
        {% set actions = {'vibration':'Vibrazione', 'tilt':'Inclinazione', 'drop':'Caduta'} %}
        {{ actions[trigger.to_state.state] if trigger.to_state.state in actions.keys() else 'Incognito'}}

The condition rejects a state whose length is zero.

Hello,
your script work very good!!
Great!!!

Thank you so much

1 Like

You’re welcome! Glad to hear it works well for you.

Please mark my (previous) post as the Solution. Only you, the author of this topic, can do that. After you select the Solution tag, my post will become easier to find for other users (who may be seeking a similar solution for the Xiaomi vibration sensor). A checkmark will also appear next to the topic’s title, indicating it has been solved.