Add support for query_template to SQL integration

Same situation here. I’m trying to look up a friendly base station name from a BSSID string, and I can’t find any examples of dynamically constructing the query based on other sensor values. Was this ever resolved?

FWIW, here’s what I’m currently using. It’s a little more concise than using a whole bunch of if statements. (Not sure my BSSID’s could be used maliciously, but I’ll mask parts of them with ** anyway.) It returns the friendly name if it’s on the list, or just the BSSID string if it isn’t.

        value_template: >
          {% set apid = (states('sensor.redmi_note_8_pro_wifi_bssid')) %}
          {% set bssidmapper =  {
            '74:da:88:**:**:2e' : 'HOME: Main Deco 2.4GHz',
            '74:da:88:**:**:2f' : 'HOME: Main Deco 5GHz',
            '74:da:88:**:**:6e' : 'HOME: Upstairs Deco 2.4GHz',
            '74:da:88:**:**:6f' : 'HOME: Upstairs Deco 5GHz',
            '74:da:88:**:**:0e' : 'HOME: Conservatory Deco 2.4GHz',
            '74:da:88:**:**:0f' : 'HOME: Conservatory Deco 5GHz',
            'e4:95:6e:**:**:64' : 'HOME: VPN Router',
            '8c:19:b5:**:**:96' : 'HOME: BT Router'
          } %}
          {{ bssidmapper[apid] if apid in bssidmapper else apid }}
1 Like