Passing window.location.hash variable to script

Hi all,

I’m attempting to figure out how I can pass the url hash from Lovelace as a variable to a script. I believe it is possible(?) but I’m struggling to come up with the template.

Any help is greatly appreciated :slight_smile:

my test button tap action:

tap_action:
  action: call-service
  service: script.test_hash_variable_from_lovelace
  service_data:
    test_hash: >
      [[[ {% if window.location.hash == "#p1" %}test1{% elif window.location.hash == "#p2" %}test2{% endif %} ]]]

My test script:

sequence:
  - service: input_boolean.turn_on
    data_template:
      entity_id: 'input_boolean.{{ test_hash }}'

Figured it out!

            tap_action:
              action: call-service
              service: script.test_hash_variable_from_lovelace
              service_data:
                test_hash: >
                  [[[var hash = window.location.hash;
                  if (hash == '#p1') return 'test1';
                  if (hash == '#p2') return 'test2';
                  return 'default';]]]