Skip to content

Instantly share code, notes, and snippets.

@dj0001
Last active June 8, 2018 11:23
Show Gist options
  • Save dj0001/095d59c30f30edd3788c13472f2aa9a6 to your computer and use it in GitHub Desktop.
Save dj0001/095d59c30f30edd3788c13472f2aa9a6 to your computer and use it in GitHub Desktop.
weather warnings from Meteoalarm on philipshue

meteoalarm-hue

light changes color for weather warnings ma

Metoalarm is a web site that provides up-to-date weather warnings for most of Europe.

API

Download the batchfile and doubleclick it.
If you use windows < win10 1803 you need to download cURL

Input Default Description
region IT013 Country[Number]
bridge localhost:8000/api/newdeveloper [ip/api/]username
light 1 [/]id light[|group]

bridge can be passed as a parameter

Rem meteoalarm-Warnmodul (win10 1803), parameter addresse, region from rss
@echo off & SETLOCAL EnableDelayedExpansion
set reg=IT013
set /p reg="Enter region from meteosat.eu(%reg%) "
rem it country
set cc=%reg:~0,2%
for %%L IN (a b c d e f g h i j k l m n o p q r s t u v w x y z) DO SET cc=!cc:%%L=%%L!
if /i %cc% EQU %reg% (set reg=%cc%) else (set reg=%cc%/%reg%)
if "%bridge%"=="" set bridge=http://localhost:8000/api/newdeveloper
if "%1"=="" (set /p bridge="change bridge adress(%bridge%) ") else (set bridge=%1)
rem olddeveloper search ip
if /i "%bridge:/=%"=="%bridge%" (for /f delims^=^"^ tokens^=8 %%i in ('curl -X GET https://www.meethue.com/api/nupnp -k -s') do set _hueip=%%i
set bridge=http://%_hueip%/api/%bridge%)
set light=1
set /p light="select light(%light%) "
rem /0 group, s/3 sensor
if /i "%light:/=%"=="%light%" ((if %light% gtr 50 echo invalid light)& set patha=lights/%light%/state) else (set patha=groups%light%/action)
if /i not "%light:s/=%"=="%light%" (set patha=sensor%light%/state)
where curl >nul 2>nul
if %ERRORLEVEL% neq 0 (echo use win10 1803 or download curl)
if /i "%reg:/=%"=="%reg%" (set tok=18) else (set tok=12)
:START
for /f "tokens=%tok% delims=<>" %%i in ('
curl -# "https://meteoalarm.eu/documents/rss/%reg%.rss" ^|find "level"
') do set res=%%i & goto endLoop
:endLoop
if NOT DEFINED res (echo maybe region not found & set res= )
set res=%res:"=%
rem warnlevel edit here, 1=Minor
set wl=1
set hue=21840& set level=1
if /i not "%res:level:5=%"=="%res%" (echo Extreme & set hue=60060& set level=5)
if %hue%==21840 if /i not "%res:level:4=%"=="%res%" (echo Severe & if %wl% LEQ 3 (set hue=0& set level=4))
if %hue%==21840 if /i not "%res:level:3=%"=="%res%" (echo Moderate & if %wl% LEQ 2 (set hue=5460& set level=3))
if %hue%==21840 if /i not "%res:awt:5 level:2=%"=="%res%" (echo Heat & if %wl% LEQ 1 (set hue=49140& set level=2))
if %hue%==21840 if /i not "%res:level:2=%"=="%res%" (echo Minor & if %wl% LEQ 1 (set hue=10920& set level=2))
if %hue%==21840 if /i not "%res:level:1=%"=="%res%" (echo no warnings) else (if /i not "%res:level:=%"=="%res%" (echo no data & set level=0))
rem ,\"on\":\"true\"
if /i "%patha:sensors/=%"=="%patha%" (set data={\"hue\":\"%hue%\"}) else (set data={\"status\":\"%level%\"})
curl -H "Content-Type:application/json" -X PUT -d %data% %bridge%/%patha%
timeout 300 /nobreak
GOTO START
pause
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment