Dark Sky - consolidate to single sensor

I’m working on an an external display that uses HA’s web-sockets to gather the data. For my weather, I’m using the dark sky sensors.

The current dark sky integration creates a dark sky sensor per data point, leading to MANY sensors to watch for over web-sockets. I would prefer to see a single dark sky sensor that contains all of the data points as attributes. This would then be fed over the w-s as JSON.

Is this possible? Has anyone else looked at doing this? Is there an easy way to accomplish this without having to delve into the dark sky integration and change it?

I’ve used Node-RED to get all the dark sky data in JSON format, you could use that to send over websocket, not perfect but you may be able to also send to data to HA from Node-RED also

I would think you could create this yourself - without Node-red - just using a template sensor with all the dark sky sensors being templates into a json output…

1 Like

Thanks for that. Looks like a template sensor is exactly what I was looking for.

I’ve spent the past several hours trying to figure out how to create a template sensor that (essentially) stores multiple values. No luck. I’ve looked at the Jinja2 documentation, and there is a way to concatenate strings, but this doesn’t seem to store the results for easy retrieval afterward.

Can anyone point me to a way to do this?

Confused. Does the template below not do what you want? It takes a few of the various dark sky sensors and formats that into a single json string:

{
"hourly": "{{states.sensor.dark_sky_hourly_summary.state}}",
"humidity": "{{states.sensor.dark_sky_humidity.state}}",
"temperature": "{{states.sensor.dark_sky_apparent_temperature.state}}" 
}
1 Like

Thank you, that was the incantation I was looking for!

It seems there is a maximum length for the state field of a sensor. When tried to consolidate all the different dark sky sensors into one, I get the following error:

homeassistant.exceptions.InvalidStateError: Invalid state encountered for entity id: sensor.dark_sky. State max length is 255 characters.

Can anyone think of another way around this?

For reference, here is my sensor.yaml entry for the consolidated sensor:

- platform: template
  sensors:
    dark_sky:
       value_template: >
         { "apparent_temperature": {{states('sensor.dark_sky_apparent_temperature') | round(0)}},
           "apparent_temperature_0h": {{states('sensor.dark_sky_apparent_temperature_0h') | round(0)}},
           "apparent_temperature_1h": {{states('sensor.dark_sky_apparent_temperature_1h') | round(0)}},
           "apparent_temperature_2h": {{states('sensor.dark_sky_apparent_temperature_2h') | round(0)}},
           "apparent_temperature_3h": {{states('sensor.dark_sky_apparent_temperature_3h') | round(0)}},
           "apparent_temperature_4h": {{states('sensor.dark_sky_apparent_temperature_4h') | round(0)}},
           "apparent_temperature_5h": {{states('sensor.dark_sky_apparent_temperature_5h') | round(0)}},
           "apparent_temperature_6h": {{states('sensor.dark_sky_apparent_temperature_6h') | round(0)}},
           "apparent_temperature_7h": {{states('sensor.dark_sky_apparent_temperature_7h') | round(0)}},
           "apparent_temperature_8h": {{states('sensor.dark_sky_apparent_temperature_8h') | round(0)}},
           "apparent_temperature_9h": {{states('sensor.dark_sky_apparent_temperature_9h') | round(0)}},
           "apparent_temperature_10h": {{states('sensor.dark_sky_apparent_temperature_10h') | round(0)}},
           "apparent_temperature_11h": {{states('sensor.dark_sky_apparent_temperature_11h') | round(0)}},
           "apparent_temperature_12h": {{states('sensor.dark_sky_apparent_temperature_12h') | round(0)}},
           "daytime_high_temperature_0d": {{states('sensor.dark_sky_daytime_high_temperature_0d') | round(0)}},
           "daytime_high_temperature_1d": {{states('sensor.dark_sky_daytime_high_temperature_1d') | round(0)}},
           "daytime_high_temperature_2d": {{states('sensor.dark_sky_daytime_high_temperature_2d') | round(0)}},
           "daytime_high_temperature_3d": {{states('sensor.dark_sky_daytime_high_temperature_3d') | round(0)}},
           "daytime_high_temperature_4d": {{states('sensor.dark_sky_daytime_high_temperature_4d') | round(0)}},
           "icon": "{{states('sensor.dark_sky_icon')}}",
           "icon_0d": "{{states('sensor.dark_sky_icon_0d')}}",
           "icon_1d": "{{states('sensor.dark_sky_icon_1d')}}",
           "icon_2d": "{{states('sensor.dark_sky_icon_2d')}}",
           "icon_3d": "{{states('sensor.dark_sky_icon_3d')}}",
           "icon_4d": "{{states('sensor.dark_sky_icon_4d')}}",
           "icon_0h": "{{states('sensor.dark_sky_icon_0h')}}",
           "icon_1h": "{{states('sensor.dark_sky_icon_1h')}}",
           "icon_2h": "{{states('sensor.dark_sky_icon_2h')}}",
           "icon_3h": "{{states('sensor.dark_sky_icon_3h')}}",
           "icon_4h": "{{states('sensor.dark_sky_icon_4h')}}",
           "icon_5h": "{{states('sensor.dark_sky_icon_5h')}}",
           "icon_6h": "{{states('sensor.dark_sky_icon_6h')}}",
           "icon_7h": "{{states('sensor.dark_sky_icon_7h')}}",
           "icon_8h": "{{states('sensor.dark_sky_icon_8h')}}",
           "icon_9h": "{{states('sensor.dark_sky_icon_9h')}}",
           "icon_10h": "{{states('sensor.dark_sky_icon_10h')}}",
           "icon_11h": "{{states('sensor.dark_sky_icon_11h')}}",
           "icon_12h": "{{states('sensor.dark_sky_icon_12h')}}",
           "overnight_low_temperature_0d": {{states('sensor.dark_sky_overnight_low_temperature_0d') | round(0)}},
           "overnight_low_temperature_1d": {{states('sensor.dark_sky_overnight_low_temperature_1d') | round(0)}},
           "overnight_low_temperature_2d": {{states('sensor.dark_sky_overnight_low_temperature_2d') | round(0)}},           
           "overnight_low_temperature_3d": {{states('sensor.dark_sky_overnight_low_temperature_3d') | round(0)}},
           "overnight_low_temperature_4d": {{states('sensor.dark_sky_overnight_low_temperature_4d') | round(0)}},                      
           "precip_probability": {{states('sensor.dark_sky_precip_probability') | round(0)}},
           "precip_probability_0d": {{states('sensor.dark_sky_precip_probability_0d') | round(0)}},
           "precip_probability_1d": {{states('sensor.dark_sky_precip_probability_1d') | round(0)}},
           "precip_probability_2d": {{states('sensor.dark_sky_precip_probability_2d') | round(0)}},
           "precip_probability_3d": {{states('sensor.dark_sky_precip_probability_3d') | round(0)}},
           "precip_probability_4d": {{states('sensor.dark_sky_precip_probability_4d') | round(0)}},
           "precip_probability_0h": {{states('sensor.dark_sky_precip_probability_0h') | round(0)}},
           "precip_probability_1h": {{states('sensor.dark_sky_precip_probability_1h') | round(0)}},
           "precip_probability_2h": {{states('sensor.dark_sky_precip_probability_2h') | round(0)}},
           "precip_probability_3h": {{states('sensor.dark_sky_precip_probability_3h') | round(0)}},
           "precip_probability_4h": {{states('sensor.dark_sky_precip_probability_4h') | round(0)}},
           "precip_probability_5h": {{states('sensor.dark_sky_precip_probability_5h') | round(0)}},
           "precip_probability_6h": {{states('sensor.dark_sky_precip_probability_6h') | round(0)}},
           "precip_probability_7h": {{states('sensor.dark_sky_precip_probability_7h') | round(0)}},
           "precip_probability_8h": {{states('sensor.dark_sky_precip_probability_8h') | round(0)}},
           "precip_probability_9h": {{states('sensor.dark_sky_precip_probability_9h') | round(0)}},
           "precip_probability_10h": {{states('sensor.dark_sky_precip_probability_10h') | round(0)}},
           "precip_probability_11h": {{states('sensor.dark_sky_precip_probability_11h') | round(0)}},
           "precip_probability_12h": {{states('sensor.dark_sky_precip_probability_12h') | round(0)}},
           "summary": "{{states('sensor.dark_sky_summary')}}",
           "summary_0d": "{{states('sensor.dark_sky_summary_0d')}}",
           "summary_1d": "{{states('sensor.dark_sky_summary_1d')}}",
           "summary_2d": "{{states('sensor.dark_sky_summary_2d')}}",
           "summary_3d": "{{states('sensor.dark_sky_summary_3d')}}",
           "summary_4d": "{{states('sensor.dark_sky_summary_4d')}}",
           "summary_0h": "{{states('sensor.dark_sky_summary_0h')}}",
           "summary_1h": "{{states('sensor.dark_sky_summary_1h')}}",
           "summary_2h": "{{states('sensor.dark_sky_summary_2h')}}",
           "summary_3h": "{{states('sensor.dark_sky_summary_3h')}}",
           "summary_4h": "{{states('sensor.dark_sky_summary_4h')}}",
           "summary_5h": "{{states('sensor.dark_sky_summary_5h')}}",
           "summary_6h": "{{states('sensor.dark_sky_summary_6h')}}",
           "summary_7h": "{{states('sensor.dark_sky_summary_7h')}}",
           "summary_8h": "{{states('sensor.dark_sky_summary_8h')}}",
           "summary_9h": "{{states('sensor.dark_sky_summary_9h')}}",
           "summary_10h": "{{states('sensor.dark_sky_summary_10h')}}",
           "summary_11h": "{{states('sensor.dark_sky_summary_11h')}}",
           "summary_12h": "{{states('sensor.dark_sky_summary_12h')}}",
           "temperature": {{states('sensor.dark_sky_temperature') | round(0)}},
           "temperature_0h": {{states('sensor.dark_sky_temperature_0h') | round(0)}},
           "temperature_1h": {{states('sensor.dark_sky_temperature_1h') | round(0)}},
           "temperature_2h": {{states('sensor.dark_sky_temperature_2h') | round(0)}},
           "temperature_3h": {{states('sensor.dark_sky_temperature_3h') | round(0)}},
           "temperature_4h": {{states('sensor.dark_sky_temperature_4h') | round(0)}},
           "temperature_5h": {{states('sensor.dark_sky_temperature_5h') | round(0)}},
           "temperature_6h": {{states('sensor.dark_sky_temperature_6h') | round(0)}},
           "temperature_7h": {{states('sensor.dark_sky_temperature_7h') | round(0)}},
           "temperature_8h": {{states('sensor.dark_sky_temperature_8h') | round(0)}},
           "temperature_9h": {{states('sensor.dark_sky_temperature_9h') | round(0)}},
           "temperature_10h": {{states('sensor.dark_sky_temperature_10h') | round(0)}},
           "temperature_11h": {{states('sensor.dark_sky_temperature_11h') | round(0)}},
           "temperature_12h": {{states('sensor.dark_sky_temperature_12h') | round(0)}},
           "uv_index": {{states('sensor.dark_sky_uv_index') | round(0)}},
           "uv_index_0d": {{states('sensor.dark_sky_uv_index_0d') | round(0)}},
           "uv_index_1d": {{states('sensor.dark_sky_uv_index_1d') | round(0)}},
           "uv_index_2d": {{states('sensor.dark_sky_uv_index_2d') | round(0)}},
           "uv_index_3d": {{states('sensor.dark_sky_uv_index_3d') | round(0)}},
           "uv_index_4d": {{states('sensor.dark_sky_uv_index_4d') | round(0)}},
           "uv_index_0h": {{states('sensor.dark_sky_uv_index_0h') | round(0)}},
           "uv_index_1h": {{states('sensor.dark_sky_uv_index_1h') | round(0)}},
           "uv_index_2h": {{states('sensor.dark_sky_uv_index_2h') | round(0)}},
           "uv_index_3h": {{states('sensor.dark_sky_uv_index_3h') | round(0)}},
           "uv_index_4h": {{states('sensor.dark_sky_uv_index_4h') | round(0)}},
           "uv_index_5h": {{states('sensor.dark_sky_uv_index_5h') | round(0)}},
           "uv_index_6h": {{states('sensor.dark_sky_uv_index_6h') | round(0)}},
           "uv_index_7h": {{states('sensor.dark_sky_uv_index_7h') | round(0)}},
           "uv_index_8h": {{states('sensor.dark_sky_uv_index_8h') | round(0)}},
           "uv_index_9h": {{states('sensor.dark_sky_uv_index_9h') | round(0)}},
           "uv_index_10h": {{states('sensor.dark_sky_uv_index_10h') | round(0)}},
           "uv_index_11h": {{states('sensor.dark_sky_uv_index_11h') | round(0)}},
           "uv_index_12h": {{states('sensor.dark_sky_uv_index_12h') | round(0)}},
           "visibility": {{states('sensor.dark_sky_visibility') | round(0)}},
           "visibility_0d": {{states('sensor.dark_sky_visibility_0d') | round(0)}},
           "visibility_1d": {{states('sensor.dark_sky_visibility_1d') | round(0)}},
           "visibility_2d": {{states('sensor.dark_sky_visibility_2d') | round(0)}},
           "visibility_3d": {{states('sensor.dark_sky_visibility_3d') | round(0)}},
           "visibility_4d": {{states('sensor.dark_sky_visibility_4d') | round(0)}},
           "visibility_0h": {{states('sensor.dark_sky_visibility_0h') | round(0)}},
           "visibility_1h": {{states('sensor.dark_sky_visibility_1h') | round(0)}},
           "visibility_2h": {{states('sensor.dark_sky_visibility_2h') | round(0)}},
           "visibility_3h": {{states('sensor.dark_sky_visibility_3h') | round(0)}},
           "visibility_4h": {{states('sensor.dark_sky_visibility_4h') | round(0)}},
           "visibility_5h": {{states('sensor.dark_sky_visibility_5h') | round(0)}},
           "visibility_6h": {{states('sensor.dark_sky_visibility_6h') | round(0)}},
           "visibility_7h": {{states('sensor.dark_sky_visibility_7h') | round(0)}},
           "visibility_8h": {{states('sensor.dark_sky_visibility_8h') | round(0)}},
           "visibility_9h": {{states('sensor.dark_sky_visibility_9h') | round(0)}},
           "visibility_10h": {{states('sensor.dark_sky_visibility_10h') | round(0)}},
           "visibility_11h": {{states('sensor.dark_sky_visibility_11h') | round(0)}},
           "visibility_12h": {{states('sensor.dark_sky_visibility_12h') | round(0)}} }

try using an attribute, they are not limited to 255 chars

I looked, but do not see a way to set an attribute of a value_template sensor. Do you have any examples you can point to?

try this