Why is this test result false
when the attribute current_position
is in fact 50 ?
Check:
Why is this test result false
when the attribute current_position
is in fact 50 ?
Check:
download the trace file and post it here (properly formatted), and also post the yaml of your automation or script.
Here’s my YAML:
alias: Solarium cover close 50%
description: ""
trigger:
- platform: numeric_state
entity_id:
- sensor.lumi_light_outside_illuminance
for:
hours: 0
minutes: 2
seconds: 0
above: 10000
condition:
- condition: state
entity_id: weather.forecast_homeass_ema
state: sunny
- alias: "Only run if the following condition is NOT met:"
condition: not
conditions:
- condition: state
entity_id: cover.shutter_solarium
attribute: current_position
state: "50"
alias: Position of shutter solarium is 50% ?
action:
- service: cover.close_cover
target:
entity_id: cover.shutter_solarium
data: {}
alias: "Service: Close shutter Solarium"
- delay:
hours: 0
minutes: 0
seconds: 16
milliseconds: 0
- service: cover.stop_cover
metadata: {}
data: {}
target:
entity_id: cover.shutter_solarium
mode: single
And here is the trace:
{
"trace": {
"last_step": "action/3",
"run_id": "2339398da7a218d3823e9bfddf1bc4b0",
"state": "stopped",
"script_execution": "finished",
"timestamp": {
"start": "2024-07-28T06:36:33.491696+00:00",
"finish": "2024-07-28T06:36:49.947751+00:00"
},
"domain": "automation",
"item_id": "1721890282258",
"trigger": "numeric state of sensor.lumi_light_outside_illuminance",
"trace": {
"trigger/0": [
{
"path": "trigger/0",
"timestamp": "2024-07-28T06:36:33.491859+00:00",
"changed_variables": {
"this": {
"entity_id": "automation.solarium_cover_close_50",
"state": "on",
"attributes": {
"id": "1721890282258",
"last_triggered": "2024-07-27T06:22:04.972144+00:00",
"mode": "single",
"current": 0,
"friendly_name": "Solarium cover close 50%"
},
"last_changed": "2024-07-27T19:58:57.085312+00:00",
"last_reported": "2024-07-27T19:58:57.085312+00:00",
"last_updated": "2024-07-27T19:58:57.085312+00:00",
"context": {
"id": "01J3TWCR1X5N91ZX797488ZTMQ",
"parent_id": null,
"user_id": null
}
},
"trigger": {
"id": "0",
"idx": "0",
"alias": null,
"platform": "numeric_state",
"entity_id": "sensor.lumi_light_outside_illuminance",
"below": null,
"above": 10000,
"from_state": {
"entity_id": "sensor.lumi_light_outside_illuminance",
"state": "9961",
"attributes": {
"state_class": "measurement",
"unit_of_measurement": "lx",
"device_class": "illuminance",
"friendly_name": "Light Outside Illuminance"
},
"last_changed": "2024-07-28T06:34:03.706336+00:00",
"last_reported": "2024-07-28T06:34:03.706336+00:00",
"last_updated": "2024-07-28T06:34:03.706336+00:00",
"context": {
"id": "01J3W0QNHTGJ9DWR0NAVF7HG6G",
"parent_id": null,
"user_id": null
}
},
"to_state": {
"entity_id": "sensor.lumi_light_outside_illuminance",
"state": "10048",
"attributes": {
"state_class": "measurement",
"unit_of_measurement": "lx",
"device_class": "illuminance",
"friendly_name": "Light Outside Illuminance"
},
"last_changed": "2024-07-28T06:34:33.489271+00:00",
"last_reported": "2024-07-28T06:34:33.489271+00:00",
"last_updated": "2024-07-28T06:34:33.489271+00:00",
"context": {
"id": "01J3W0RJMHS6DED96JN8ZVRKB4",
"parent_id": null,
"user_id": null
}
},
"for": {
"__type": "<class 'datetime.timedelta'>",
"total_seconds": 120
},
"description": "numeric state of sensor.lumi_light_outside_illuminance"
}
}
}
],
"condition/0": [
{
"path": "condition/0",
"timestamp": "2024-07-28T06:36:33.491994+00:00",
"result": {
"result": true
}
}
],
"condition/0/entity_id/0": [
{
"path": "condition/0/entity_id/0",
"timestamp": "2024-07-28T06:36:33.492142+00:00",
"result": {
"result": true,
"state": "sunny",
"wanted_state": "sunny"
}
}
],
"condition/1": [
{
"path": "condition/1",
"timestamp": "2024-07-28T06:36:33.492379+00:00",
"result": {
"result": true
}
}
],
"condition/1/conditions/0": [
{
"path": "condition/1/conditions/0",
"timestamp": "2024-07-28T06:36:33.492491+00:00",
"result": {
"result": false
}
}
],
"condition/1/conditions/0/entity_id/0": [
{
"path": "condition/1/conditions/0/entity_id/0",
"timestamp": "2024-07-28T06:36:33.492604+00:00",
"result": {
"result": false,
"state": 100,
"wanted_state": "50"
}
}
],
"action/0": [
{
"path": "action/0",
"timestamp": "2024-07-28T06:36:33.494393+00:00",
"changed_variables": {
"context": {
"id": "01J3W0W7TKDTTPQMXC47TD3BJB",
"parent_id": "01J3W0RJMHS6DED96JN8ZVRKB4",
"user_id": null
}
},
"result": {
"params": {
"domain": "cover",
"service": "close_cover",
"service_data": {},
"target": {
"entity_id": [
"cover.shutter_solarium"
]
}
},
"running_script": false
}
}
],
"action/1": [
{
"path": "action/1",
"timestamp": "2024-07-28T06:36:33.669178+00:00",
"result": {
"delay": 16,
"done": true
}
}
],
"action/2": [
{
"path": "action/2",
"timestamp": "2024-07-28T06:36:49.671151+00:00",
"result": {
"enabled": false
}
}
],
"action/3": [
{
"path": "action/3",
"timestamp": "2024-07-28T06:36:49.671479+00:00"
}
]
},
"config": {
"id": "1721890282258",
"alias": "Solarium cover close 50%",
"description": "",
"trigger": [
{
"platform": "numeric_state",
"entity_id": [
"sensor.lumi_light_outside_illuminance"
],
"for": {
"hours": 0,
"minutes": 2,
"seconds": 0
},
"above": 10000
}
],
"condition": [
{
"condition": "state",
"entity_id": "weather.forecast_homeass_ema",
"state": "sunny"
},
{
"alias": "Only run if the following condition is NOT met:",
"condition": "not",
"conditions": [
{
"condition": "state",
"entity_id": "cover.shutter_solarium",
"attribute": "current_position",
"state": "50",
"alias": "Position of shutter solarium is 50% ?"
}
]
}
],
"action": [
{
"service": "cover.close_cover",
"target": {
"entity_id": "cover.shutter_solarium"
},
"data": {},
"alias": "Service: Close shutter Solarium"
},
{
"delay": {
"hours": 0,
"minutes": 0,
"seconds": 16,
"milliseconds": 0
}
},
{
"service": "cover.set_cover_position",
"target": {
"entity_id": "cover.shutter_solarium"
},
"data": {
"position": 50
},
"alias": "Service: Set cover position Solarium to 50%",
"enabled": false
},
{
"device_id": "b94b8c2c181e7b3a1f934d574d045528",
"domain": "cover",
"entity_id": "7d1d416537c3ba0a83958dff8b5b0bac",
"type": "stop"
}
],
"mode": "single"
},
"blueprint_inputs": null,
"context": {
"id": "01J3W0W7TKDTTPQMXC47TD3BJB",
"parent_id": "01J3W0RJMHS6DED96JN8ZVRKB4",
"user_id": null
}
},
"logbookEntries": [
{
"name": "Solarium cover close 50%",
"message": "triggered by numeric state of sensor.lumi_light_outside_illuminance",
"source": "numeric state of sensor.lumi_light_outside_illuminance",
"entity_id": "automation.solarium_cover_close_50",
"context_id": "01J3W0W7TKDTTPQMXC47TD3BJB",
"when": 1722148593.4929812,
"domain": "automation"
},
{
"when": 1722148595.277998,
"state": "closed",
"entity_id": "cover.shutter_solarium",
"context_event_type": "automation_triggered",
"context_domain": "automation",
"context_name": "Solarium cover close 50%",
"context_message": "triggered by numeric state of sensor.lumi_light_outside_illuminance",
"context_source": "numeric state of sensor.lumi_light_outside_illuminance",
"context_entity_id": "automation.solarium_cover_close_50"
}
]
}
My objective is to close the cover 50% on sunny days when the sunlight reaches above 10000, unless the cover is already closed 50%.
You have a not condition.
So the state should not be 50 when it passes.
I know, but the posted test result did not include the NOT part, so you can ignore that.
I’m not sure you can.
Try and add the condition without the not and see what happens.
Or use numeric condition instead
Here is something strange; I followed you advise, and removed the NOT part, but the test still failed.
Then I changed the value from string to integer, and then it passes:
But the strange part is that it was the GUI who made the string (quotes). I didn’t. And I was under the impression that state values always are returned as string values (?)
cause as soon as I set the vaule as an integer, and return to the GUI editor, I get this error/warning:
in the trace that you posted, the conditions did pass and the actions were invoked. it passed because the value of “current_position” was 100. and it was looking for 50. so that failed. but then the “not” made that failure become ‘true’.
i don’t know if the strong or not string thing is actually the issue or a red herring. if i were you, i’d look at the traces more. (or post them here, and i’m happy to look). but in any case the reason why the trace you posted “passed” the not condition is clear from this snippet:
"condition/1": [
{
"path": "condition/1",
"timestamp": "2024-07-28T06:36:33.492379+00:00",
"result": {
"result": true
}
}
],
"condition/1/conditions/0": [
{
"path": "condition/1/conditions/0",
"timestamp": "2024-07-28T06:36:33.492491+00:00",
"result": {
"result": false
}
}
],
"condition/1/conditions/0/entity_id/0": [
{
"path": "condition/1/conditions/0/entity_id/0",
"timestamp": "2024-07-28T06:36:33.492604+00:00",
"result": {
"result": false,
"state": 100,
"wanted_state": "50"
}
}
],
Thanks for your time and effort.
I tried to read the trace log, but i was very confused. I couldn’t even figure out if the most recent steps were at the end of the trace log file or at the beginning.
Then i did a number of test and trace reviews, and i got a feeling all of them were in that log I posted (?), so I’m unsure how to limit the log to only a specific trace?
An entity’s state
value is a string.
An entity’s attribute value can be integer, float, string, list, dict, boolean, etc.
Your State Condition is configured to check the value of an attribute (current_position) so it isn’t limited to being a string (it’s actually an integer).
That’s one of the Automation Editor’s quirks. It defaults to saving the value as a string. That’s fine if testing the entity’s state
property, because it’s always a string, but counterproductive when testing an attribute’s value which is not always a string.
You can even see this behavior in the trace. The attribute’s value is 100
(an integer) and the value it’s compared to is the 50
you entered but converted to a string "50"
.
"state": 100,
"wanted_state": "50"
Ah, those many small details that isn’t obvious, not even consistent. HA is a wonderful tool, but all too often a small leak will sink a great ship!
if it wasn’t clear, this is the check from that trace. you see where it says the state is 100, but it wanted 50. then the result is false. this is for condition 1 (zero based) sub condition 0.
this then made the parent condition 1 “true”
"condition/1": [
{
"path": "condition/1",
"timestamp": "2024-07-28T06:36:33.492379+00:00",
"result": {
"result": true
}
}
because of the “not” that you had.
I agree. I dislike this particular quirk because it makes it challenging for me to provide users with examples where the State Trigger/Condition refers to an attribute.
I’ll supply a YAML example where the attribute’s value is not quoted, like a boolean true
, the user pastes it into the editor or recreates it via the UI, saves it and the value typically gets converted to string "true"
. Afterwards, the user reports my example doesn’t work. Only after they post the YAML of their version is it discovered what the Automation Editor did.
Ok, thanks anyway for helping. It’s working now, but I’m afraid I probably will forget this “quirk” the next time I need to make an automation with focus on attributes