I would like so set a REST sensor, but do directly some templating on it. It is not delivering a well formated JSON, but I don’t hink that doesn’t matter for my problem.
If I try
- platform: rest
name: Next Full Moon
resource: http://wannistvollmond.celll.net?api=1
value_template: >
{{ value ~ "dddd" }}
scan_interval: 21600
I agree it’s puzzling. From all outward appearances, strptime should be able to process the string.
In similar cases that I have encountered, the cause was the presence of unprintable characters in the string (like nulls). The unprintable character isn’t displayed but it’s present so it interferes with filters, like strptime, that attempt to process the string.
If it does contain unprintable characters (and that’s just speculation) they must be removed. If there’s a null character at the end of the string, the trim filter might remove it (I say “might” because I don’t know for sure what kind of characters it removes beyond spaces and tabs).
As a first experiment, try this version. It simply uses trim to remove leading and trailing whitespace.
If that fails to fix the problem, try this version. It converts the value to a slug (a string containing only alphanumeric characters and underscores), changes underscores to spaces, removes leading and trailing whitespace, then uses a slightly different pattern in strptime to convert the string to a datetime object.
If that also fails to fix the problem, I’m not sure what else can be done. Maybe there are no unprintable characters and it’s due to something completely different.