Scrape sensor logic?

Trying to get the scrape sensor to work for picking up the spot gold price and %-change using the id-tag. Can someone please help with the code.

  - platform: scrape
    resource: https://goldprice.org/spot-gold.html
    select: "#gpxtickerLeft_price,#gpxtickerLeft_price_chg_pc"
    value_template: '{{ value.split(",") If gpxtickerLeft_price_chg < 0 then "Down" else "Up"}}'
    attribute: 
      price: gpxtickerLeft_price
      change: gpxtickerLeft_price_chg_p
    name: Spot Gold

Have you considered using yahoofinance.

Here is the configuration.yaml code and the gold symbol

# Track stock symbols every 20 minutes
yahoofinance:
  symbols: 
    - F*GC.CMX
  scan_interval:
    minutes: 20
  show_trending_icon: true
  decimal_places: 2

You can create a page in lovelace to view and the data will be archived in database.

1 Like