## Drivstoffpris ##
- sensor:
name: fuel_prices_command
scan_interval: 3600
command: >
petrolDataTokenResponse=$(curl -s "https://api.drivstoffappen.no/api/v1/authorization-sessions") &&
petrolDataToken=$(echo "$petrolDataTokenResponse" | jq -r '.token') &&
tokenBytes=$(echo -n "$petrolDataToken" | xxd -p -c 256) &&
first=$(echo -n "$tokenBytes" | head -c 2) &&
rest=$(echo -n "$tokenBytes" | tail -c +3) &&
tokenBytesShifted="${rest}${first}" &&
tokenShifted=$(echo -n "$tokenBytesShifted" | xxd -r -p) &&
md5Hash=$(echo -n "$tokenShifted" | md5sum -b | awk '{print $1}') &&
md5Hash=$(echo "$md5Hash" | tr '[:upper:]' '[:lower:]') &&
X_API_KEY="$md5Hash" &&
X_CLIENT_ID="com.raskebiler.drivstoff.appen.ios" &&
petrolData=$(echo "$petrolDataResponse" | jq -c '.') &&
echo "{\"verdi\":" $(
curl -s -H "X-API-KEY: $X_API_KEY" -H "X-CLIENT-ID: $X_CLIENT_ID" "https://api.drivstoffappen.no/api/v1/stations?stationTypeId=1"
| jq -c '[ .[] | select( .id | contains(33, 34, 35, 62, 67, 89, 105, 126, 1083, 4456, 5887)) ]'
) "}"
value_template: >
{{ value_json.verdi | length }}
json_attributes:
- verdi