I am trying to move over from Alexa, we have multiple HA voice assistants working. The correct entities are exposed, and I have had to wrap some external api calls as yaml switches. I am now going through all our popular Alexa commands. The above command cannot process the “for 5 minutes” the lights are left on ,with no error. Any ideas how to solve this?
#Ok Nabu - Turn on the patio light for 5 minutes
1 messages · Page 1 of 1 (latest)
If it's okay to use an LLM based Assist pipeline you could write a script that takes 2 parameters (a list of lights and a duration) and expose that script to Assist. Provide details for the AI on how to use the script in the script's description. It should then pick up your request and call the script and provide the mentioned lights and duration.
Thanks , I will try to unpick your answer . I wonder how Alexa does it.
With magic of similar scripts to the one suggested to you. It's just written by Amazon employees.
Generally, we already have pending commands, and you can say “turn off the lights in 5 minutes”. But this functionality seems to be broken if the llm agent is selected😕 .
Your request is a bit more complex, I think creating custom sentences would completely solve your problem if you are using built-in intents.
I tried this , but It is matching HassTurnOn intent_script:
TurnOnLightWithTimer:
speech:
text: "Turn [on] [the] {{ name }} lights for {{ duration }}"
action:
- service: light.turn_on
target:
entity_id: "light.{{ name | lower | replace(' ', '') }}"
- delay: "{{ duration }}"
- service: light.turn_off
target:
entity_id: "light.{{ name | lower | replace(' ', '') }}"
It would be interesting to solve the problem, but I encountered a problem when using the {name} variable.
turnontimer:
data:
- sentences:
- “Turn on {name} for {tm}”
turnontimer:
action:
- action: light.turn_on
target:
entity_id: “{{ name }}”
speech:
text: “ok”
I'm pretty sure I was getting the entity_id in the script a year ago, not the requested name (friendly_name or aliases).
Apparently I need to proceed by analogy with rooms - area_entities(area), but there is no such function for entities. And the documentation on this issue has not been updated.
Or am I missing something? The sentence parser understands that it should return id for the {name} variable, but it doesn't pass targets: to the script.
intent:
name: turnontimer
slots:
name: torch
tm: 5 minutes
details:
name:
name: name
value: torch
text: torch
tm:
name: tm
value: 5 minutes
text: 5 minutes
targets:
light.yeelight_ceil26_0x12ebfa38:
matched: true
match: true
sentence_template: turn on {name} for {tm}
unmatched_slots: {}
source: custom
When actually running the intent, the target gets the torch value and everything fails.
@verbal thicket I know you solved the problem with aliases for area and floors, maybe you can clarify this issue too?
if we manage to deal with the previous question (I would like to find a simple solution rather than parsing core.entity_registry), it is better to use a script.turn_on - this will finalize the intent, and the actions will be run in a parallel process.
action: script.turn_on
data:
entity_id: script.turn_off_light_with_delay
variables:
name: “{{ name }}”
time: “{{ tm }}”
Additionally, the script will need to organize the logic to handle the time variable to account for seconds, minutes and hours.
From the output of developer / assist it does not not appear to be even considering my intent script
Reload the dialogs and intent_script modules
Also, instead of using the {name} global variable, you can take your time and create a list with devices. Not very versatile, but it solves the problem
lists:
my_light:
values:
- in: "torch"
out: "light.yeelight_ceil26_0x12ebfa38"
# Don't forget to define the variable for time
tm:
wildcard: true
I guess you can check how inbuilt intents work (HassTurnOn). I guess for entity ID you want to have some restrictions on the slot (not like a wildcard, but domain and stuff). But i suppose you have that already...
Don't have access to my config rn to check, if i have some custom usages for entity slot.
The point is, I looked at the homeassistant\helpers\intent.py file. The logic of its operation is clear (async_match_targets and _filter_by_name), but based on the actual result, these mechanisms don’t apply to custom sentences. It seems we need another function, say get_entity_id(name_or_alias_or_id), that should perform similar target-matching actions, but this hasn’t been implemented to date. So, the question is withdrawn.
just had a quick look at the code, final question - where are the individual internal intents definded eg HassTurnOn
sorry - found it
The working solution is ready, you will only have to adapt to your language.
If I didn't need Aliases, it's much easier to solve everything, just by searching for friendly_names in the required domains . https://github.com/mitrokun/custome_sentences/blob/main/start_with_timer.yaml
Looks great thanks , will get my head around it tomorrow
I just checked this out. It does the command correctly (turns on light) and sets the timer, but after the designated time the timer goes off but the light does not get turned off. Is it supposed to?
Did you replace unit.startswith('сек') with unit.startswith('sec')? And similarly for minutes. Even without this change, the program should use the default value [00:00:10]. I tested commands with different durations — everything works correctly. If your light turned on, then the variable was transferred. Try viewing the trace of the light_with_delay script for more details.
I just looked at the yaml code. It is showing tons of errors. Here is what i did. I DL the yaml file from your link. Using File Browser I imported it to the Custom Sentences directory. When I then opened it it shows multiple errors. I tried to copy some of it to post but the errors dont copy. I think one of the messages when i first opened it was that it couldn't be parsed so was being ignored. I'm sure it is something my system is not set up correctly for or user error.
This is not a ready-made file, but instructions. You need to create parser.py and specify the path to it in the configuration file.
Automation and scripts must be created via the GUI.
Ah, ok. I'll wait for the final product. Thanks
This is the final product. I have some thoughts about the need to process duplicate names, but I'm unlikely to implement this. If you need detailed instructions, just show this file to any LLM—it should explain the details.
Ok Thanks
am testing parser.py it works with some entities, but I am testing the actual on/off with a tuya light "side light" parser.py does not find it and when I print out all the entities in the search loop grep does not find "side light" yet it is found in developer tools/states and matches to light.side_light . I dont know how to create an alias
Does light.side_light have a friendly_name attribute? //I understand the reason. If Name was not specified, the friendly_name attribute will be generated automatically from the entity_id, but will not be added to the registry.
was exposed - no alias , parser works now 😆 will carry on testing