Hi. Thanks for a great project.
I am having some trouble working with the data_generator.
I am trying to read output of the GitHub - toringer/home-assistant-met-next-6-hours-forecast: Met.no next 6 hours forecast component for Home Assistant integration, which gives the forecast as a json text.
I would like to plot the temperature of this forecast and so need to parse the datetime string and native_temperature fo the json object, which looks like this:
forecast_json: [{"native_temperature": 2.8, "native_templow": 1.1, "native_precipitation": 3.5, "precipitation_probability": 86.0, "datetime": "2024-11-17T16:00:00+00:00", "condition": "snowy-rainy", "native_pressure": 987.6, "wind_bearing": 321.1, "native_wind_speed": 8.1}, {"native_temperature": 2.7, "native_templow": 1.7, "native_precipitation": 6.9, "precipitation_probability": 99.6, "datetime": "2024-11-17T22:00:00+00:00", "condition": "snowy-rainy", "native_pressure": 989.6, "wind_bearing": 276.8, "native_wind_speed": 7.3}, {"native_temperature": 2.0, "native_templow": 1.3, "native_precipitation": 16.5, "precipitation_probability": 97.2, "datetime": "2024-11-18T04:00:00+00:00", "condition": "snowy-rainy", "native_pressure": 986.9, "wind_bearing": 291.1, "native_wind_speed": 7.3}, {"native_temperature": 2.0, "native_templow": 1.3, "native_precipitation": 3.9, "precipitation_probability": 84.9, "datetime": "2024-11-18T10:00:00+00:00", "condition": "snowy-rainy", "native_pressure": 990.9, "wind_bearing": 318.6, "native_wind_speed": 8.3}, {"native_temperature": 1.0, "native_templow": 0.6, "native_precipitation": 1.4, "precipitation_probability": 69.5, "datetime": "2024-11-18T16:00:00+00:00", "condition": "snowy", "native_pressure": 993.2, "wind_bearing": 210.1, "native_wind_speed": 3.0}, {"native_temperature": 0.9, "native_templow": -0.1, "native_precipitation": 0.0, "precipitation_probability": 43.6, "datetime": "2024-11-18T22:00:00+00:00", "condition": "cloudy", "native_pressure": 991.0, "wind_bearing": 169.5, "native_wind_speed": 4.0}, {"native_temperature": -0.4, "native_templow": -1.4, "native_precipitation": 0.0, "precipitation_probability": 27.1, "datetime": "2024-11-19T04:00:00+00:00", "condition": "partlycloudy", "native_pressure": 992.7, "wind_bearing": 56.5, "native_wind_speed": 1.9}, {"native_temperature": -0.1, "native_templow": -2.1, "native_precipitation": 0.0, "precipitation_probability": 10.6, "datetime": "2024-11-19T10:00:00+00:00", "condition": "partlycloudy", "native_pressure": 995.2, "wind_bearing": 179.2, "native_wind_speed": 1.7}, {"native_temperature": -2.2, "native_templow": -3.2, "native_precipitation": 0.0, "precipitation_probability": 6.6, "datetime": "2024-11-19T16:00:00+00:00", "condition": "partlycloudy", "native_pressure": 996.2, "wind_bearing": 167.9, "native_wind_speed": 1.9}, {"native_temperature": -1.6, "native_templow": -3.3, "native_precipitation": 0.0, "precipitation_probability": 2.0, "datetime": "2024-11-20T00:00:00+00:00", "condition": "partlycloudy", "native_pressure": 997.0, "wind_bearing": 216.8, "native_wind_speed": 0.7}, {"native_temperature": -1.9, "native_templow": -3.5, "native_precipitation": 0.0, "precipitation_probability": 3.9, "datetime": "2024-11-20T06:00:00+00:00", "condition": "partlycloudy", "native_pressure": 1001.8, "wind_bearing": 107.5, "native_wind_speed": 3.4}, {"native_temperature": -1.9, "native_templow": -3.0, "native_precipitation": 0.0, "precipitation_probability": 3.9, "datetime": "2024-11-20T12:00:00+00:00", "condition": "cloudy", "native_pressure": 1002.7, "wind_bearing": 74.2, "native_wind_speed": 4.2}, {"native_temperature": -3.0, "native_templow": -4.0, "native_precipitation": 0.0, "precipitation_probability": 5.9, "datetime": "2024-11-20T18:00:00+00:00", "condition": "cloudy", "native_pressure": 1002.9, "wind_bearing": 67.1, "native_wind_speed": 4.4}, {"native_temperature": -3.8, "native_templow": -5.2, "native_precipitation": 0.0, "precipitation_probability": 11.8, "datetime": "2024-11-21T00:00:00+00:00", "condition": "cloudy", "native_pressure": 1001.9, "wind_bearing": 61.7, "native_wind_speed": 4.5}, {"native_temperature": -4.3, "native_templow": -5.3, "native_precipitation": 0.0, "precipitation_probability": 15.7, "datetime": "2024-11-21T06:00:00+00:00", "condition": "cloudy", "native_pressure": 998.7, "wind_bearing": 53.1, "native_wind_speed": 4.7}, {"native_temperature": -4.3, "native_templow": -4.7, "native_precipitation": 0.0, "precipitation_probability": 27.5, "datetime": "2024-11-21T12:00:00+00:00", "condition": "cloudy", "native_pressure": 994.6, "wind_bearing": 36.4, "native_wind_speed": 4.6}, {"native_temperature": -4.7, "native_templow": -5.9, "native_precipitation": 0.0, "precipitation_probability": 35.3, "datetime": "2024-11-21T18:00:00+00:00", "condition": "cloudy", "native_pressure": 991.5, "wind_bearing": 29.2, "native_wind_speed": 4.6}, {"native_temperature": -5.5, "native_templow": -6.6, "native_precipitation": 2.0, "precipitation_probability": 25.5, "datetime": "2024-11-22T00:00:00+00:00", "condition": "snowy", "native_pressure": 989.0, "wind_bearing": 33.6, "native_wind_speed": 4.1}, {"native_temperature": -5.3, "native_templow": -6.6, "native_precipitation": 0.0, "precipitation_probability": 11.8, "datetime": "2024-11-22T06:00:00+00:00", "condition": "cloudy", "native_pressure": 985.5, "wind_bearing": 61.0, "native_wind_speed": 2.3}, {"native_temperature": -5.2, "native_templow": -6.2, "native_precipitation": 0.0, "precipitation_probability": 13.7, "datetime": "2024-11-22T12:00:00+00:00", "condition": "cloudy", "native_pressure": 985.3, "wind_bearing": 203.7, "native_wind_speed": 2.0}, {"native_temperature": -5.2, "native_templow": -7.1, "native_precipitation": 0.0, "precipitation_probability": 21.6, "datetime": "2024-11-22T18:00:00+00:00", "condition": "cloudy", "native_pressure": 985.6, "wind_bearing": 205.5, "native_wind_speed": 2.1}, {"native_temperature": -5.1, "native_templow": -6.3, "native_precipitation": 0.0, "precipitation_probability": 13.7, "datetime": "2024-11-23T00:00:00+00:00", "condition": "cloudy", "native_pressure": 987.4, "wind_bearing": 199.7, "native_wind_speed": 2.1}, {"native_temperature": -3.4, "native_templow": -5.5, "native_precipitation": 0.0, "precipitation_probability": 13.7, "datetime": "2024-11-23T06:00:00+00:00", "condition": "cloudy", "native_pressure": 988.2, "wind_bearing": 199.8, "native_wind_speed": 2.0}, {"native_temperature": -3.4, "native_templow": -5.3, "native_precipitation": 0.0, "precipitation_probability": 23.5, "datetime": "2024-11-23T12:00:00+00:00", "condition": "cloudy", "native_pressure": 989.1, "wind_bearing": 201.3, "native_wind_speed": 2.3}, {"native_temperature": -3.7, "native_templow": -5.8, "native_precipitation": 0.0, "precipitation_probability": 25.5, "datetime": "2024-11-23T18:00:00+00:00", "condition": "cloudy", "native_pressure": 990.2, "wind_bearing": 200.3, "native_wind_speed": 2.4}, {"native_temperature": -3.7, "native_templow": -6.7, "native_precipitation": 0.0, "precipitation_probability": 19.6, "datetime": "2024-11-24T00:00:00+00:00", "condition": "partlycloudy", "native_pressure": 992.3, "wind_bearing": 196.8, "native_wind_speed": 2.3}, {"native_temperature": -1.6, "native_templow": -5.4, "native_precipitation": 0.0, "precipitation_probability": 15.7, "datetime": "2024-11-24T06:00:00+00:00", "condition": "cloudy", "native_pressure": 993.7, "wind_bearing": 198.0, "native_wind_speed": 2.6}, {"native_temperature": -1.6, "native_templow": -3.3, "native_precipitation": 0.0, "precipitation_probability": 19.6, "datetime": "2024-11-24T12:00:00+00:00", "condition": "cloudy", "native_pressure": 992.7, "wind_bearing": 199.3, "native_wind_speed": 2.7}, {"native_temperature": -2.2, "native_templow": -3.2, "native_precipitation": 0.0, "precipitation_probability": 27.5, "datetime": "2024-11-24T18:00:00+00:00", "condition": "cloudy", "native_pressure": 994.7, "wind_bearing": 199.6, "native_wind_speed": 2.7}, {"native_temperature": -2.2, "native_templow": -4.0, "native_precipitation": 1.7, "precipitation_probability": 25.5, "datetime": "2024-11-25T00:00:00+00:00", "condition": "snowy", "native_pressure": 994.5, "wind_bearing": 200.5, "native_wind_speed": 2.6}, {"native_temperature": -1.8, "native_templow": -4.8, "native_precipitation": 0.0, "precipitation_probability": 17.6, "datetime": "2024-11-25T06:00:00+00:00", "condition": "partlycloudy", "native_pressure": 994.7, "wind_bearing": 203.8, "native_wind_speed": 2.9}, {"native_temperature": -1.4, "native_templow": -1.8, "native_precipitation": 0.0, "precipitation_probability": 23.5, "datetime": "2024-11-25T12:00:00+00:00", "condition": "cloudy", "native_pressure": 998.8, "wind_bearing": 206.5, "native_wind_speed": 2.8}, {"native_temperature": -0.4, "native_templow": -1.5, "native_precipitation": 1.5, "precipitation_probability": 23.5, "datetime": "2024-11-25T18:00:00+00:00", "condition": "snowy", "native_pressure": 999.2, "wind_bearing": 199.2, "native_wind_speed": 3.0}, {"native_temperature": -0.4, "native_templow": -1.4, "native_precipitation": 0.0, "precipitation_probability": 31.4, "datetime": "2024-11-26T00:00:00+00:00", "condition": "cloudy", "native_pressure": 998.7, "wind_bearing": 198.4, "native_wind_speed": 3.0}, {"native_temperature": -0.5, "native_templow": -1.9, "native_precipitation": 0.0, "precipitation_probability": 17.6, "datetime": "2024-11-26T06:00:00+00:00", "condition": "cloudy", "native_pressure": 1002.7, "wind_bearing": 199.0, "native_wind_speed": 3.0}, {"native_temperature": -0.5, "native_templow": -1.4, "native_precipitation": 0.0, "precipitation_probability": 25.5, "datetime": "2024-11-26T12:00:00+00:00", "condition": "cloudy", "native_pressure": 1003.6, "wind_bearing": 201.6, "native_wind_speed": 3.0}, {"native_temperature": -0.8, "native_templow": -2.4, "native_precipitation": 0.0, "precipitation_probability": 25.5, "datetime": "2024-11-26T18:00:00+00:00", "condition": "partlycloudy", "native_pressure": 1008.8, "wind_bearing": 200.9, "native_wind_speed": 3.2}, {"native_temperature": -1.0, "native_templow": -4.5, "native_precipitation": 2.0, "precipitation_probability": 31.4, "datetime": "2024-11-27T00:00:00+00:00", "condition": "snowy", "native_pressure": 1008.5, "wind_bearing": 204.4, "native_wind_speed": 2.9}, {"native_temperature": -0.3, "native_templow": -2.8, "native_precipitation": 0.0, "precipitation_probability": 25.5, "datetime": "2024-11-27T06:00:00+00:00", "condition": "cloudy", "native_pressure": 1012.2, "wind_bearing": 202.9, "native_wind_speed": 2.8}]
Notice how datetime has a “T” between the day and the hour, making this a non-standard timestamp.
What I have tried is:
data_generator: |
let p=[];
let forecast = entity.attributes.forecast_json ;
for (var i=0; i<8;i++)
{
// datetime is format as "2024-11-17T19:00:00+00:00
let curDate = forecast[i].datetime;
p[i] = [moment(curDate,'YYYY-MM-DDTHH:mm:ss+00:00').valueOf(),forecast[i].native_temperature];
}
return p;
but nothing is displayed.
If I remove the formatting string '‘YYYY-MM-DDTHH:mm:ss+00:00’ from moment()
the plot becomes a vertical line, which to me indicates that there is something not right about the reading of the timestamps.
Any idea what this does not work?
(In cases like this, do I have any way of debugging the javascript code in the data_generator field?)