Sensor Select

Hi Folks. I am trying to write a sensor to get a value from a page that contains this HTML:

<a id="power" class="unit" onclick="newAJAXCommand('zones.cgi?zone=0');" style="background: rgb(51, 153, 255);"></a>

I am trying to get the value 255 – the third number in the background color of the #power selector. This HTML is nested a few DIVs deep.

I’m trying to use the Select of “.unit” in the scrap configuration options, and “background” as the attribute. I’ve also tried “.power” and had no luck. No matter what I do, I’m getting “unknown” as a value from the sensor.

Could anybody suggest how I might best go about this? I have been reading up on the Select field and beautifulsoup, but I feel like I’m missing something more fundamental since all I’m seeing in the senor value is “Unknown” and the only log error is " * Index ‘0’ not found in sensor.web_scrape"


To select by ID you would use “#power” and not “.power”. I would note that I have had similar issues with people that write horrible HTML and have multiple HTML elements with the same ID. Where the browser is forgiving, the author should be shot as nothing on the page should carry the same ID.

And as a second note, while HA people tried to create a GUI to use for Scrape, I find it terrible and I use YAML to make it easier to adjust and evaluate. Take this for example:

  - resource:
      - name: Starting Goalie BuildID
        unique_id: sensor.starting_goalie_buildid
        select: '#__NEXT_DATA__'
        value_template: >
            {{ value | regex_findall('buildId":\s?"([a-zA-Z0-9_-]{1,99})"') | first }}

You cannot (easily) write that value_template in the GUI considering all the quotes … I threw away any use of the GUI for YAML configuration.

Thanks for this. I tried #power with the attribute ‘style’ and got the same ‘unknown’ result.

I will try moving it to configuration.yaml.

How am I meant to debug this? How do I see what data is being returned to the senor, selected by select etc?