Automation Error: Error executing script. Invalid data for call_service at pos 1: required key not provided @ data['topic']

Hello Everybody,

I’m new to Home Assistant and started to learn automations. I want to turn my Projector On by pressing a button on my UI. The projector turns on using a Tasmota IR Blaster. This setup already works in a different scenario using HTTP-Post or using the MQTT Developer Tools in Home Assistant. But getting this running from an automation is killing me. I’m just looking at the action part at the moment.

Thats the part in my automation.yaml which is not working

  - id: '1591999113709'
  alias: Beamer Off
  description: ''
  trigger:
  - entity_id: input_boolean.tv_on_off
    from: 'Off'
    platform: state
    to: 'On'
  condition: []
  action:
  - data:
      payload: '{"Protocol":"NEC","Bits":32,"Data":"0x00FD9A65"}'
      topic: cmnd/IR_LR/IRSend
    service: mqtt.publish

configuration.yaml looks like this:

# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:

#calendar 27.05.2020
google:
  client_id: blablabla.apps.googleusercontent.com
  client_secret: notsoimportant

# Text to speech
tts:
  - platform: google_translate

#sensors
sensor:
#Fritzbox 28.05.2020
  - platform: fritzbox_callmonitor
    name: callmon
    username: justsomeuser
    password: andaverysecretpasswort
    phonebook: 1
    prefixes:
      - '+49'
      - '+49123'
      - '1234'
variable:
  caller_information:
    value: 'Unknown'
    restore: true
    attributes:
      icon: mdi:phone-in-talk
      name: Anruferinformation

group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
#Themes iOS 30.05.2020
frontend:
  themes: !include_dir_merge_named themes

When I run the Automation by clicking “Execution” I get the following error:

Beamer Off: Error executing script. Invalid data for call_service at pos 1: required key not provided @ data[‘topic’]

Can someone explain to me what Key is required? According to the documentation of mqtt.publish all what is needed is the topic and payload?!

Any help is much appreciated.

Thank you very much

The error is saying you have not provided a topic. Which is odd, because you have.

Here’s one of mine that works for comparison:

  action:
    service: mqtt.publish
    data:
      payload: "ON"
      topic: 'home-assistant/variable/night_vision_active'

Other than home assistant putting the order of the keys alphabetically (does not matter, just makes it hard for humans to read), the only difference I see is the single quotes around the topic value. Give that a go.

you could try using payload_template instead of payload.

like this:

- data:
      payload_template: {"Protocol":"NEC","Bits":32,"Data":"0x00FD9A65"}
      topic: cmnd/IR_LR/IRSend
    service: mqtt.publish

I pasted your automation into my test system, corrected the indentation error, reloaded automations, then manually triggered the automation using Developer Tools > Services.

Screenshot from 2020-06-13 15-59-48

There was no error message reported in the log and the payload was successfully published to the topic (perhaps the initial indentation issue throws the whole thing off).

Screenshot from 2020-06-13 16-02-39

Given that I cannot replicate the problem using the same automation, it’s difficult to explain why you are seeing the error message.

Only thing I can add is that the automation’s trigger states are incorrect. An input_boolean’s states are lowercase 'on' and 'off'. In addition, as mentioned, the first line of your automation is indented incorrectly. It should look like this:

- id: '1591999113709'
  alias: Beamer Off
  description: ''
  trigger:
  - entity_id: input_boolean.tv_on_off
    from: 'off'
    platform: state
    to: 'on'
  condition: []
  action:
  - data:
      payload: '{"Protocol":"NEC","Bits":32,"Data":"0x00FD9A65"}'
      topic: cmnd/IR_LR/IRSend
    service: mqtt.publish

@123 Thank you very much, this did the trick. I’m not 100% sure what was the problem but it is working now!

1 Like