esphome / issues

Issue Tracker for ESPHome
https://esphome.io/
290 stars 34 forks source link

data_template for homeassistant.event action must be explicitly defined as a lambda #5394

Open Slalamander opened 7 months ago

Slalamander commented 7 months ago

The problem

When using data_template and accompanying variables tag in the homeassistant.event action, the lambda code for the variables must be explicitly declared as a lambda (using !lambda). The provided example in the api documentation (which is for homeassistant.service) does not do this.

In the yaml snippet, brightness_inp is defined in the explicit way, whereas range_inp is defined as shown in the documentation. In the additional information, brightness is set to the input value integer, whereas range is the lambda code as defined in the ESP config.

I'm not sure if this is a bug or an error in the documentation, however.

Which version of ESPHome has the issue?

2023.12.6

What type of installation are you using?

pip

Which version of Home Assistant has the issue?

2024.1.2

What platform are you using?

ESP32

Board

az-delivery-devkit-v4

Component causing the issue

api

Example YAML snippet

- homeassistant.event:
          event: esphome.led_panel_range_set
          data_template:
            brightness: '{{ brightness_inp }}'
            range: '{{ range_inp }}'
          variables:
            brightness_inp: !lambda 'return brightness_val;'
            range_inp: |-
              return id(led_strip_rgb_range).state;

Anything in the logs that might be useful for us?

No response

Additional information

The event data is returned in home assistant as:

event_type: esphome.led_panel_range_set
data:
  device_id: xxx
  brightness: 100
  range: return id(led_strip_rgb_range).state;
origin: LOCAL
time_fired: "xxx"
context:
  id: xxx
  parent_id: null
  user_id: null
ssieb commented 7 months ago

Looks like a code issue. It appears that the intention was to match the docs, but the implementation isn't quite right.

github-actions[bot] commented 3 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.