Trigger_id as value for brightness

Hi, I’m trying to do a simple automation and use the “trigger.id” as the value for the brightness of the light bulb. see below:

alias: Trappa dimra upp och ned
description: ""
trigger:
  - platform: time
    at: "22:00:00"
    id: "15"
  - platform: time
    at: "07:00:00"
    id: "80"
condition: []
action:
  - service: light.turn_on
    data:
      brightness_pct: "{{ trigger.id | float }}"
    target:
      entity_id: light.trappa_hall
mode: single

I get the following error:

Error: Error rendering data template: UndefinedError: ‘dict object’ has no attribute ‘id’

When I do not use “{{ trigger.id | float }}” but just “{{ trigger.id }}” I get this error instead:

expected float for dictionary value @ data[‘brightness_pct’]

Any suggestions to what is wrong here and how to fix it?

I looked at my climate automation and changed the float to float(0) which works with the climate service but still not solving my problem with the light service…

This works for the climate:

alias: CLIMATE Molnet
description: Control molnet based on precense
trigger:
  - platform: state
    entity_id:
      - input_boolean.alarm_on
    to: "on"
    for:
      hours: 0
      minutes: 30
      seconds: 0
    id: "16"
  - platform: state
    entity_id:
      - input_boolean.alarm_on
    to: "off"
    for:
      hours: 0
      minutes: 2
      seconds: 0
    id: "18"
  - platform: time
    at: "22:00:00"
    id: "16"
condition: []
action:
  - service: climate.set_temperature
    data:
      temperature: "{{trigger.id | float(0) }}"
    target:
      entity_id:
        - climate.molnet
mode: single

How are you triggering this automation?

Make sure you read this

Especially the testing part

I’m triggering it by time, at 2200 and 0700, similar to my other automation. I’m testing it by doing a “run” and then “trace” and then getting the error from the “trace”

Ok, I now read this part:

Please note that if you click on Trigger of an automation in the frontend, only the action part will be executed by Home Assistant. That means you can’t test your trigger or condition part that way. It also means that if your automation uses some data from triggers, it won’t work properly as well just because trigger is not defined in this scenario.

All this makes that Trigger feature pretty limited and nearly useless for debugging purposes so you need to find another way. Make sure you check and adapt to your circumstances appropriate examples from Automation Trigger, Conditions and Actions.

And I checked the automation now and adding the “{{trigger.id | float(0) }}” solved my problem. Thank you

That is not really the solution.
You are just masking the main issue which is you are not triggering the automation.
Just edit the automation trigger time if you want to test your automation.

Yes, for future I will use a “custom” trigger to test just the automation part and then just add the trigger after the testing :slight_smile:

I still had to use the “float” part for my automation to work, but I had a similar issue where I had to convert the trigger.id type