I want to know if there’s a way to call a service, that returns a boolean value, from a template condtion. I can’t seem to find any examples of this and my understanding of HA isn’t quite that good. What I’d like to acheive:
alias: Do the thing
sequence:
- conditions: {{ CALL.SERVICE(param1, param2) }}
- service: alarm_control_panel.alarm_arm_away
data: {}
target:
entity_id: alarm_control_panel.my_alarm
mode: single
icon: mdi:shield
For context, I want to build a script that is given a code from the frontend and if that code matches a list of known codes executes some action, like turning off an alarm. I know there are other ways of doing the checking but doing it through a service means I can add additional configuration around the checking. I’ve already written the basic service that given a code will check it against values in the configuration but I can’t find any examples/documentation of services being called in templates.
Those are some interesting ideas, the macro I haven’t seen before and will be good options if using the service is not possible.
However, I’m still looking to find if I can use the service call to validate my code/password as it gives me a lot more flexibility than hard coding passwords in my scripts.
Tryting to call the service from the template was approaching the problem the wrong way but given that documentation it seems like this should be possible:
If I got it right, response_variable goes together with the new stop verb/action, and that would be set in my_service.check_secret as the variable returned, i.e. True/False in this case.
Not sure why you point to Dev documentation, that’s definitely out of scope here.
Yeah I should have been more clear. Based on that dev documentation there’s some specifics I need to do on the service side in order for the service to properly respond into the response_variable. It seems like assuming my service is built correctly I can get the result into a varaible and then check the result in a condition
There are several ways to confirm the supplied password is correct (many have already been suggested in this topic) but none can do it the way you initially requested (call a service within a Template Condition).
A service can be a “yaml script”, as Tom pointed out. In that case, the doc is irrelevant.
A service can also be offered by an integration, coded in Python, and there the doc is relevant.
Are you planning to create a custom component in python that will implement your password logic?