aex351 / home-assistant-neerslag-card

Display Buienalarm and/or Buienradar data in a graph for Home Assistant.
29 stars 3 forks source link

Cloudflare 502 Bad Gateway #20

Closed Zendio closed 3 years ago

Zendio commented 3 years ago

I'm using the configuration as per example on the main page:

sensor:
  - platform: command_line
    command: python3 -c "import requests; import json; import random; dataRequest = requests.get('https://cdn-secure.buienalarm.nl/api/3.4/forecast.php?lat=<lat-3-decimals>&lon=<lon-3-decimals>&region=nl&unit=mm%2Fu&c='+str(random.randint(0,999999999999999)) ).text; dataRequest = dataRequest.replace('\r\n',' '); data = '{\"data\":'+dataRequest+'}';    print(data);"
    name: Neerslag_Buienalarm_Regen_Data
    json_attributes:
      - data
    value_template: 'last_changed: {{states.sensor.neerslag_buienalarm_regen_data.last_changed | default(now())}}'
    scan_interval: 240

I have lat/lon set correctly. Sometimes the sensor works, but often times it doesn't. The HA log tells me the command returns a 502 Bad Gateway error, originating from Cloudflare. Using my webbrowser to visit https://cdn-secure.buienalarm.nl/api/3.4/forecast.php?lat=SCRAMBLED&lon=SCRAMBLED&region=nl works every time.

Is there anything we/I can do so I don't trigger the gateway error and at the same time have rain data populated all the time?

Thanks in advance, Eric