Calling a service in a template condition

My bad, I didn’t realize “service” could have multiple meanings. Yes, I’ve written a custom component that offers a service to do the checking logic.

I thought my problem was on the configuration side but it’s actually on the integration side which is out of scope here as you said.

The answers provided to my original question are right: No you can’t do it in a condition

But, if you have an integration with a service built to return results and are using HA >= 2023.7, you should be able to do something along the lines of:

sequence:
  - service: my_service.check_secret
    data:
      value: NoTaReAlPaSsWoRd
    response_variable: check_result
  - condition: template
    value_template: "{{ check_result.value }}"
  - service: system_log.write
    data:
      level: info
      message: Check successful

Well, the value_template won’t be just {{ check_result }}, it’ll have to extract the key from the dictionary. response variables can only be dictionaries. So, it will be something like "{{ check_result.value }}"

1 Like

… deleted …

What petro said …

Okeee :slight_smile:

If/when you get it working with the return value, please do a follow-up here.
I for sure would be interested to see a A to Z solution in action👍

1 Like

I managed to get this working.

Using my integration here (I’m still getting it to pass validation at the time of writing, so ignore that) I added the following to my configuration.yaml:

secret_service:
    secrets:
        - secret: secret_a
          value: sUpErSeCrEt

Then I added the following script for testing purposes:

alias: Test
sequence:
  - service: secret_service.check_secret
    data:
      name: secret_a
      value: sUpErSeCrEt
    response_variable: check_result
  - condition: template
    value_template: "{{ check_result.result == 'success' }}"
  - service: system_log.write
    data:
      level: info
      message: Check successful
mode: single
icon: mdi:test-tube

Not a full A-Z solution yet but most of the way there, it should be easy enough to throw a value from the front end into this script and have it working

1 Like