I copied that last line into my script. Now it gives me this error: Error rendering data template: UndefinedError: ‘dict object’ has no attribute ‘value’
Do you mean the script or the automation? It should be in the automation, not the script. If that is the case, open the automation editor, at the top right click “Traces”. If there are traces, click the 3-dot menu at the top right, select “Download json” and paste the contents here properly formatted.
Why not use the easy option of a custom made Integration for exactly this?
Sorry I meant Automation. And there is only “download trace” and no “download json”. I screen shot that page here.
I hope this would suffice since I don’t know how to properly format the coding in this forum.
I changed the time on line 11 to “12:00” only for testing purpose, so I can tests this during the day.
I think it used to be call “Download json”… but “Download trace” is what you should post.
No, we need to be able to see the what part is failing and why… Community Guidelines - How to Ask a Good Question - Format it Correctly
That would involve downloading something from Github? Another can of warm I am not ready to open yet.
Did you change the value for t1
in the script to 21:00
or whatever value is reasonable for testing based on your current local time? In the light.turn_on
service call, the value for the template must render to between 0-100… or it will error out.
I tried download trace three times, each time it saved as json file. How do I upload that here? Yes I changed the starting time in the script to match the testing starting time.
NO, it’s in HACS.
Open it in any Text editor, copy/paste.
OK, here it is.
{
"trace": {
"last_step": "action/1",
"run_id": "22861f803918616f64a8ed9620ca786d",
"state": "stopped",
"script_execution": "error",
"timestamp": {
"start": "2024-02-08T02:04:56.655184+00:00",
"finish": "2024-02-08T02:04:56.677072+00:00"
},
"domain": "automation",
"item_id": "1706944419680",
"error": "Error rendering data template: UndefinedError: 'dict object' has no attribute 'value'",
"trigger": null,
"trace": {
"trigger": [
{
"path": "trigger",
"timestamp": "2024-02-08T02:04:56.655417+00:00",
"changed_variables": {
"this": {
"entity_id": "automation.new_automation",
"state": "on",
"attributes": {
"id": "1706944419680",
"last_triggered": "2024-02-08T02:01:43.546816+00:00",
"mode": "single",
"current": 0,
"friendly_name": "Kitchen Lights Dim"
},
"last_changed": "2024-02-08T02:01:39.573204+00:00",
"last_updated": "2024-02-08T02:01:43.566434+00:00",
"context": {
"id": "01HP3763BTX1XAHCD6SJCSF1NB",
"parent_id": "01HP3763BSYSSEV0Q07QK28HWJ",
"user_id": null
}
},
"trigger": {
"platform": null
}
}
}
],
"action/0": [
{
"path": "action/0",
"timestamp": "2024-02-08T02:04:56.659731+00:00",
"child_id": {
"domain": "script",
"item_id": "1707096702958",
"run_id": "bad3f10e3e3aa4a29389aa4896f88202"
},
"changed_variables": {
"context": {
"id": "01HP37BZYFR6SNWYWR01PX6G9R",
"parent_id": "01HP37BZYEQCQMZKQ7AAGC0Y6C",
"user_id": null
},
"brightness": {}
},
"result": {
"params": {
"domain": "script",
"service": "1707096702958",
"service_data": {},
"target": {}
},
"running_script": true
}
}
],
"action/1": [
{
"path": "action/1",
"timestamp": "2024-02-08T02:04:56.669630+00:00",
"error": "Error rendering data template: UndefinedError: 'dict object' has no attribute 'value'"
}
]
},
"config": {
"id": "1706944419680",
"alias": "Kitchen Lights Dim",
"description": "Dim LIghts gradually after 9 pm",
"trigger": [
{
"platform": "state",
"entity_id": [
"light.kitchen_main_lights"
],
"to": "on"
}
],
"condition": [
{
"condition": "time",
"after": "17:00:00",
"before": "05:00:00",
"weekday": [
"sun",
"mon",
"tue",
"wed",
"thu",
"fri",
"sat"
]
}
],
"action": [
{
"service": "script.1707096702958",
"metadata": {},
"data": {},
"response_variable": "brightness"
},
{
"service": "light.turn_on",
"target": {
"entity_id": "light.kitchen_main_lights"
},
"data": {
"brightness_pct": "{{ brightness.value | float(0) }}"
}
}
],
"mode": "single"
},
"blueprint_inputs": null,
"context": {
"id": "01HP37BZYFR6SNWYWR01PX6G9R",
"parent_id": "01HP37BZYEQCQMZKQ7AAGC0Y6C",
"user_id": null
}
},
"logbookEntries": [
{
"name": "Kitchen Lights Dim",
"message": "triggered",
"source": null,
"entity_id": "automation.new_automation",
"context_id": "01HP37BZYFR6SNWYWR01PX6G9R",
"when": 1707357896.655648,
"domain": "automation"
},
{
"name": "Set Dimmer level",
"message": "started",
"entity_id": "script.1707096702958",
"context_id": "01HP37BZYFR6SNWYWR01PX6G9R",
"when": 1707357896.660597,
"domain": "script",
"context_event_type": "automation_triggered",
"context_domain": "automation",
"context_name": "Kitchen Lights Dim",
"context_message": "triggered",
"context_entity_id": "automation.new_automation"
},
{
"when": 1707357896.661963,
"state": "on",
"entity_id": "script.1707096702958",
"context_event_type": "automation_triggered",
"context_domain": "automation",
"context_name": "Kitchen Lights Dim",
"context_message": "triggered",
"context_entity_id": "automation.new_automation"
},
{
"when": 1707357896.666626,
"state": "off",
"entity_id": "script.1707096702958",
"context_event_type": "automation_triggered",
"context_domain": "automation",
"context_name": "Kitchen Lights Dim",
"context_message": "triggered",
"context_entity_id": "automation.new_automation"
}
]
}
That points to the script being the source of the problem. Double check that your script itself is correct and that your automation is calling the correct script. I have tested the both version of the script I posted previously as well as a slightly simplified version of the automation you posted above and it is working as expected. I will post them together here for reference:
Script
alias: Response - Dimmer Level
variables:
brightness: >
{% set t1 = "21:00" %}
{% set t2 = now() %}
{% set t3 = today_at(t1) %}
{% set t4 = (t2 - t3).total_seconds() %}
{% set t5 = (t4/600)|round(0, floor) %}
{% set brightness_pct = 100 - 4 * t5 %}
{{ {'value': brightness_pct} }}
sequence:
- stop: Return dimmer value
response_variable: brightness
mode: queued
Automation
alias: Light - time based dimming
description: ""
trigger:
- platform: state
entity_id:
- light.example
from: "off"
to: "on"
condition:
- condition: time
after: '21:00:00'
before: '05:00:00'
action:
- service: script.response_dimmer_level
data: {}
response_variable: brightness
- service: light.turn_on
metadata: {}
data:
brightness_pct: "{{ brightness.value | float(0) }}"
target:
entity_id: light.example
mode: queued
There are several small differences that may or may not mean anything. 1) in your script, you called response_variable: brightness, I called it brightness_pct. 2) your script mode is single, I had “queued”. 3) your automation had mode as “queued” and I had “single” I changed mine to yours and made sure the starting time is about 20:00, which is about 1 hour ago my time. The result is the same error message.
{
"trace": {
"last_step": "action/1",
"run_id": "99bf3d5dc0fd4253f81b08b48cbd2a52",
"state": "stopped",
"script_execution": "error",
"timestamp": {
"start": "2024-02-08T05:02:23.971345+00:00",
"finish": "2024-02-08T05:02:23.987824+00:00"
},
"domain": "automation",
"item_id": "1706944419680",
"error": "Error rendering data template: UndefinedError: 'dict object' has no attribute 'value'",
"trigger": null,
"trace": {
"trigger": [
{
"path": "trigger",
"timestamp": "2024-02-08T05:02:23.971541+00:00",
"changed_variables": {
"this": {
"entity_id": "automation.new_automation",
"state": "on",
"attributes": {
"id": "1706944419680",
"last_triggered": "2024-02-08T04:59:14.135938+00:00",
"mode": "queued",
"current": 0,
"max": 10,
"friendly_name": "Kitchen Lights Dim"
},
"last_changed": "2024-02-08T04:59:07.005455+00:00",
"last_updated": "2024-02-08T04:59:14.150568+00:00",
"context": {
"id": "01HP3HB4AQJSS07BKT77YT5G2C",
"parent_id": "01HP3HB4AP1GA4VAR723DKJ23N",
"user_id": null
}
},
"trigger": {
"platform": null
}
}
}
],
"action/0": [
{
"path": "action/0",
"timestamp": "2024-02-08T05:02:23.974967+00:00",
"child_id": {
"domain": "script",
"item_id": "1707096702958",
"run_id": "b6f520a10fbf57e0806d5efd6c047468"
},
"changed_variables": {
"context": {
"id": "01HP3HGXQ3EKV7W6AC4BBA9TNH",
"parent_id": "01HP3HGXQ283X533EEQW1KTE30",
"user_id": null
},
"brightness": {}
},
"result": {
"params": {
"domain": "script",
"service": "1707096702958",
"service_data": {},
"target": {}
},
"running_script": true
}
}
],
"action/1": [
{
"path": "action/1",
"timestamp": "2024-02-08T05:02:23.981913+00:00",
"error": "Error rendering data template: UndefinedError: 'dict object' has no attribute 'value'"
}
]
},
"config": {
"id": "1706944419680",
"alias": "Kitchen Lights Dim",
"description": "Dim LIghts gradually after 9 pm",
"trigger": [
{
"platform": "state",
"entity_id": [
"light.kitchen_main_lights"
],
"to": "on"
}
],
"condition": [
{
"condition": "time",
"after": "20:00:00",
"before": "05:00:00",
"weekday": [
"sun",
"mon",
"tue",
"wed",
"thu",
"fri",
"sat"
]
}
],
"action": [
{
"service": "script.1707096702958",
"metadata": {},
"data": {},
"response_variable": "brightness"
},
{
"service": "light.turn_on",
"target": {
"entity_id": "light.kitchen_main_lights"
},
"data": {
"brightness_pct": "{{ brightness.value | float(0) }}"
}
}
],
"mode": "queued"
},
"blueprint_inputs": null,
"context": {
"id": "01HP3HGXQ3EKV7W6AC4BBA9TNH",
"parent_id": "01HP3HGXQ283X533EEQW1KTE30",
"user_id": null
}
},
"logbookEntries": []
}
BTW, thank you for spending time with me on this. Much appreciated.
Post the trace from script too.
Here it is.
{
"trace": {
"last_step": "sequence/0",
"run_id": "a9729e92d3dc7e8ec5831045a083fe41",
"state": "stopped",
"script_execution": "aborted",
"timestamp": {
"start": "2024-02-08T05:25:55.512356+00:00",
"finish": "2024-02-08T05:25:55.518670+00:00"
},
"domain": "script",
"item_id": "1707096702958",
"trace": {
"sequence/0": [
{
"path": "sequence/0",
"timestamp": "2024-02-08T05:25:55.516452+00:00",
"changed_variables": {
"this": {
"entity_id": "script.1707096702958",
"state": "off",
"attributes": {
"last_triggered": "2024-02-08T05:02:23.976653+00:00",
"mode": "single",
"current": 0,
"friendly_name": "Set Dimmer level"
},
"last_changed": "2024-02-08T05:02:23.979844+00:00",
"last_updated": "2024-02-08T05:02:23.979844+00:00",
"context": {
"id": "01HP3HGXQ3EKV7W6AC4BBA9TNH",
"parent_id": "01HP3HGXQ283X533EEQW1KTE30",
"user_id": null
}
},
"brightness_pct": {
"value": 64
},
"context": {
"id": "01HP3JW05R2SWP46AVH4SH493T",
"parent_id": null,
"user_id": "c42bcf0d2fbe454fb7add7579494a8b9"
}
},
"error": "'brightness'",
"result": {
"stop": "Return dimmer value",
"error": false
}
}
]
},
"config": {
"alias": "Set Dimmer level",
"variables": {
"brightness_pct": "{% set t1 = \"20:00\" %} {% set t2 = now() %} {% set t3 = today_at(t1) %} {% set t4 = (t2 - t3).total_seconds() %} {% set t5 = (t4/600)|round(0, floor) %} {% set brightness_pct = 100 - 4 * t5 %} {{ { 'value': brightness_pct} }}\n"
},
"sequence": [
{
"stop": "Return dimmer value",
"response_variable": "brightness"
}
],
"mode": "single"
},
"blueprint_inputs": null,
"context": {
"id": "01HP3JW05R2SWP46AVH4SH493T",
"parent_id": null,
"user_id": "c42bcf0d2fbe454fb7add7579494a8b9"
}
},
"logbookEntries": [
{
"when": 1707369955.513564,
"state": "on",
"entity_id": "script.1707096702958",
"context_user_id": "c42bcf0d2fbe454fb7add7579494a8b9"
},
{
"when": 1707369955.516926,
"state": "off",
"entity_id": "script.1707096702958",
"context_user_id": "c42bcf0d2fbe454fb7add7579494a8b9",
"context_state": "on",
"context_entity_id": "script.1707096702958"
}
]
}
You didn’t change the brightness_pct
in the variables section to brightness
.
you mean in the script? I just changed them and ran it again. Same error.
Okay, one last test before it’s time for drastic action…
Go to the Services tool: Link to Developer tools: services – My Home Assistant
put script.1707096702958
into the “Service” field, then click the “Call Service” button. Let us know or share a screen shot of what the Response says.