Possible to use !secret or regexp in is_state_addr?

Lately I’ve been moving all references to IP addresses from my config files to secrets.yaml to maximize security but there’s one place where I’m not sure how to proceed.

I have a template switch which is ON if a certain URL is being cast and I’m using the is_state_attr method to avoid getting unknown values.

switch:
  - platform: template
    switches:
      camera_on_tv:
        value_template: "{{ is_state_attr('media_player.chromecast_ultra', 'media_content_id', 'http://192.168.1.1234:8080/video') }}"
        turn_on:
          service: script.cast_camera
          data:
            media_player: media_player.chromecast_ultra
        turn_off:
          service: media_player.turn_off
          data:
            entity_id: media_player.chromecast_ultra

Let’s say I also have this secret:

video_url: http://192.168.1.1234:8080/video

Question 1: Is there some way I can verify if the state attribute is equal to my secret so the IP address does not need to be hardcoded in configuration.yaml?

Question 2: If there’s no easy or practical way to question 1, is there some way to use is_state_attr against some regexp just to check if what’s being cast is simply some URL ending with /video?

Thanks in advance!

In your template switch…

value_template: !secret something

in your secrets.yaml

something: "{{ is_state_attr('media_player.chromecast_ultra', 'media_content_id', 'http://192.168.1.1234:8080/video') }}"

Thanks! I didn’t think about doing it like that :slight_smile:

1 Like