So I’m trying to create a for me, advanced script, maybe its not even possible. Here’s what want to do:
I want my one button switch to toggle my light on/off and dim up and down. Since I’m new I thought hey let’s ask ChatGPT. I got a code that to me looks good but what do I know. Anyone wanna tell me what’s wrong with it? I might be a noob, but before anyone asks, of course I have changed the name of the light group entity to the real entity of the light group
input_boolean:
dim_direction:
initial: off
automation:
- alias: Toggle Your Light Group On/Off with Single Press
trigger:
platform: state
entity_id: switch.lampknapp_sovrum
action:
- service: script.toggle_light_group
- alias: Dimming Your Group with Long Press and Change Direction with Double Press
trigger:
platform: state
entity_id: switch.lampknapp_sovrum
action:
- service: script.start_dimming_group
data:
direction_entity: input_boolean.dim_direction
script:
toggle_light_group:
sequence:
- service: light.toggle
target:
entity_id: light.your_light_group # Replace with your light group entity_id
start_dimming_group:
sequence:
- condition: state
entity_id: input_boolean.dim_direction
state: 'on'
- service: input_boolean.turn_off
target:
entity_id: input_boolean.dim_direction
- service: light.turn_on
target:
entity_id: light.your_light_group # Replace with your light group entity_id
data:
brightness_step_pct: 5 # Adjust this value for the desired dimming level
- wait_template: "{{ is_state('switch.lampknapp_sovrum', 'off') }}"
- service: light.turn_off
target:
entity_id: light.your_light_group # Replace with your light group entity_id
default:
- service: input_boolean.turn_on
target:
entity_id: input_boolean.dim_direction
- service: light.turn_on
target:
entity_id: light.your_light_group # Replace with your light group entity_id
data:
brightness_step_pct: -5 # Adjust this value for the desired dimming level
Tell its author, ChatGPT, that its suggestion failed to work and to correct it.
“What’s wrong with it” is that ChatGPT has an established track record of serving up malformed examples and that’s one of them. It’s got about 90% of it right and then it throws in something that is invalid within the given context.
What kind of “button switch” and how is it integrated to Home Assistant?
EDIT
ChatGPT produced an automation to control dimming via “Long Press” and “Double Press”. However, the example’s State Trigger is monitoring the state of a switch entity. A switch reports on or off and not button events like press/release/hold/etc.
Did it suggest to use a State Trigger with a switch or did you change its original example? Just trying to measure the extent of ChatGPT’s understanding of basic concepts.
First mistake! You expected that ChatGPT would do it for you. It has never done anything right unless given a lot of help before attempting it. That’s why a lot of students are failing their studies, relying on it instead of putting in the work.
So you now need to troubleshoot it your self. We are not your next AIs, to figure out the wrong part.
Hint: there are tons of examples in many threads here in the community. Get your fingers busy.
basically, if you look at the two automations the first thing that pops out to me is that they both have exactly the same trigger. So that means that both scripts will be started at exactly the same time.
One script toggles the light group. Then nothing else.
And the other one’s first action if the boolean is on is to turn the boolean off and then turn light group on to 5%, waits for the switch to be turned off (forever?) and turns the lights back off. And if it’s not on then the script simply stops. Then nothing.
So which of those scripts get started first? You can never know as it’s totally determined by the system. I believe it’s what is referred to as a “race condition”. So will the light toggle first or will the dimming script run first? Who knows.
TBH i’m still not even sure where the input_boolean comes into play here. Are you turning it on somewhere else?
And as far as the “default:” is concerned I’m not sure what that would do since there is no branching behavior to decide whether to select some group of actions or a default group of actions.
Even if it could choose the “default” actions it just simply turns the light on to -5%. Once. Then stops.
Where exactly is the second automation looking for a “long press” and/or “double press”? I guess you could consider the forever wait for the switch to be turned back off as a “long press” but what if it never gets turned off?
As noted above the whole thing is a mess of words that seems like they should work if you have no idea what it should actually look like.
And therein lies the problem. ChatGPT tricks you into thinking that it’s “almost right” except for a tweak or two but in fact it’s almost entirely wrong. And since you don’t know what is right you have no idea how wrong it is. And then you come on here asking to tell you why it won’t work.
That’s the long answer.
The short answer is because it’s completely wrong.
I even have to keep looking at it to see if I’m completely missing something because the logic is so flawed I can’t believe how wrong it actually is. But I don’t think I am.
As a software dev, I think there’s no harm consulting ChatGPT, but as others have said, it will reliably spew out incorrect stuff.
What will be more effective for you is to find a similar automation or blueprint available here in the community, look at their yaml, and read the documentation to understand what’s involved.
That way, you gain exposure quickly to what you’re trying to perform and at the same time understanding each of the pieces that is involved. Takes some time, not as easy as asking ChatGPT, but your bioGPT (read brain) will get the training it needs.
As for why the generated script didn’t work, it’s using totally incorrect keys for the yaml. Some of those keys do not belong in an automation yaml.
Every one of those keys are actually valid and the yaml syntax is generally correct. The only key that is nonsensical is the “default:” key that randomly got stuck in there. But even that yaml key is valid in an automation/script - just not there.
And again that’s the problem. To the uninitiated it looks like it SHOULD be right. And even the config checker will be likely fooled by it because it is mostly proper syntax.
Did you intend to include empty Device Actions or did you overlook to complete them for the example? Because the Device Actions in the dim-up-longpress loop aren’t empty whereas they are in the loop for dim-down-doublepress.
For that matter, what’s the purpose of executing that repeat-until in parallel mode when the entire automation is set to restart mode?
Why use two separate choose statements when one will suffice?
For future reference, the examples rely on Device Triggers which have shortcomings in terms of portability and maintenance (see this community guide).
Have you considered browsing through Blueprints Exchange for an existing blueprint that supports your Shelly button?
Thanks for your feedback. The reason it’s set up with “choose” and “repeat” is because I could only get my ‘long_push’ to only dim 10% no matter how long I held the button pressed. I got some information and inspiration from this video (https://www.youtube.com/watch?v=L-bcabdaMxE&t=628s)
I will look at those links you posted to see if there’s anyway to make the dimming smoother instead of 10% steps. I mean, it works perfectly fine. but it want it to be perfect.[quote=“123, post:15, topic:670841, full:true”]
Did you intend to include empty Device Actions or did you overlook to complete them for the example? Because the Device Actions in the dim-up-longpress loop aren’t empty whereas they are in the loop for dim-down-doublepress.
For that matter, what’s the purpose of executing that repeat-until in parallel mode when the entire automation is set to restart mode?
Why use two separate choose statements when one will suffice?
For future reference, the examples rely on Device Triggers which have shortcomings in terms of portability and maintenance (see this community guide).
Have you considered browsing through Blueprints Exchange for an existing blueprint that supports your Shelly button?
I don’t know if you are aware of it but that entire second choose can never execute because it’s looking for a trigger.id equal to dim-down-doublepress but neither of the two Device Triggers is configured to report that.
In other words, half of the action code, in both automations, does nothing. Is that intentional, because these examples are a ‘work-in-progress’, or not?
FWIW, those two automations can be combined into one, using some simple templating, but you would need to use service calls instead of a Device Actions (service calls support templates but Device Actions don’t .
Ah, I found what you meant and no, that was still there from my first try with this automatization. I removed it. I will take a look and see how I can out combine this into one. Would be needed since there’s a few rooms id like to have this for and it would be easier to have just one for each room and not five.
You may wish to consider removing the Solution tag from that post. The example presented has far too many questionable aspects to recommend for use by new users. Wait until you have cleaned up the code.
BTW, have you had time to formulate an answer to the question of why you chose to use parallelize the repeat despite the automation’s mode being restart? Like the second choose that is never executed, the parallelization never occurs (i.e. it’s ‘dead code’).