This works fine 80% of the time, but when the detailed_description is longer than 255 characters the return value is “unknown” . I want to get the full text string without truncating the data.
You can’t put more than 256 characters in the state - that’s all it stores. So you could either truncate it to a maximum of 256 characters (or is it 255 - can’t remember), or put it in an attribute, where no such restriction exists.
I already have the Template Sensor integrated and working, so I don’t see this actually accomplishes anything over what I already have, I do get the 4 daily forecast descriptions I want unless the description text is longer that 255 characters, only then do I get “unavailable”.
But, what I want is to change the code in such a way that I’ll get the full description. What I’m envisioning is code that will give me the first part of the description and code that will give me the overflow so I can put them back together and have the full description.
raw data from the get_forcasts call gives me this:
- detailed_description: >-
Showers and thunderstorms before 10pm, then showers and thunderstorms
between 10pm and 1am, then a chance of showers and thunderstorms. Mostly
cloudy, with a low around 52. North wind 15 to 20 mph, with gusts as
high as 30 mph. Chance of precipitation is 100%. New rainfall amounts
between 1 and 2 inches possible.
This is really weird - just went into HA and checked the values for my forecast sensors, and now yours shows the detailed description truncated to 255 characters AND the attributes to be the full description, including the words full_description. I can use that !
What’s weird is that I did change state to OK and there was NO change - yes I did reload YAML templates, also ALL YAML CONFIGURATION and restarted HA - nothing changed. But if I can adapt the your code to what I need then all is good. Thank you.
Not exactly, it generates 7 12 hour forecasts, so if you execute the get_forecasts on a twice_daily in the AM you’ll get morning, evening, morning, evening, etc. If you execute get_forecasts in the afternoon, you’ll get evening, morning,…
Realistically the NWS updates the forecast at about 5 minutes after the hour all day long.
Well, that’s the basis for my question. For example, forecast[2] and forecast[3] are not necessarily day_two and day_3. If the first is 6AM to 6PM (is_daytime: true), the second will be 6PM to 6AM the following day (is_daytime: false). With the exception of forecast[0], any forecast showing is_daytime: false will straddle midnight.
Moreover, my experience is the NWS rarely updates shortly after the hour. Take a close look at this:
I agree, my labels are inaccurate, meaning they’re not day0, day1, day2, etc. but then they are just labels and I treat them as such in my use of them - I could have easily called them anything such as forecast_0, forecast_1, and so on. It’s just the way I named them. As far as the frequency goes, it’s close enough, not using them for anything other than creating a morning weather briefing played on a speaker while I’m having breakfast. I used to scrape the forecast from the NWS website but found it wasn’t as reliable as I wanted - that’s still the way I get the announced label such as “Today” , “Tonight”, “Memorial Day”, “Tomorrow Night”, etc.