From 5abe3bca8e1e0a12b160b7106c663d64f3cd1452 Mon Sep 17 00:00:00 2001 From: David Peterson Date: Wed, 3 Oct 2018 20:48:25 +1000 Subject: [PATCH] Update scrape component to add optional headers (#6455) Added headers optional parameter, plus example for BOM --- source/_components/sensor.scrape.markdown | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/source/_components/sensor.scrape.markdown b/source/_components/sensor.scrape.markdown index 047dd0e9562..47019c97a23 100644 --- a/source/_components/sensor.scrape.markdown +++ b/source/_components/sensor.scrape.markdown @@ -36,6 +36,7 @@ Configuration variables: - **authentication** (*Optional*): Type of the HTTP authentication. Either `basic` or `digest`. - **username** (*Optional*): The username for accessing the website. - **password** (*Optional*): The password for accessing the website. +- **headers** (*Optional*): Headers to use for the web request ## {% linkable_title Examples %} @@ -130,3 +131,23 @@ sensor: unit_of_measurement: "öre/kWh" ``` {% endraw %} + +### {% linkable_title BOM Weather %} + +The Australian Bureau of Meterology website returns an error if the User Agent header is not sent. + +{% raw %} +```yaml +# Example configuration.yaml entry +sensor: + - platform: scrape + resource: http://www.bom.gov.au/vic/forecasts/melbourne.shtml + name: Melbourne Forecast Summary + select: ".main .forecast p" + value_template: '{{ value | truncate(255) }}' + # Request every hour + scan_interval: 3600 + headers: + User-Agent: Mozilla/5.0 +``` +{% endraw %}