Ah, missed the split("'")
, that still doesn’t guarentee that the character ’ will be the splitting factor as you are relying on the interpreter to set the quotes. It could set the interior quotes as ". Also, the solution returns a character instead of empty if there is no stable version. While it is shorter, it still has it’s pitfalls. Using regex will return the same answer regardless of these variables.
Hi,
I have a problem since some time ago. In the past information into the engineering feed was as it’s on the screenshots above, but few months ago it changes as follow:
And I’m not sure who to break those objects into the strings.
That’s an error directly from your router. object Object is a object in js. That’s either an error in your router, or an error in the component you are using to get the information from your router. There’s nothing you can do other than:
- Update your router firmware and hope it fixes the issue.
- Update the component, if it’s a custom component.
- Log an issue with the component after you do step 1 and step 2 to verify that it’s not your setup.
This is information from the rss downloaded from MikroTik site.
Here is declaration of the sensor:
- platform: feedparser
name: "latest_mikrotik_version"
feed_url: 'https://mikrotik.com/download.rss'
date_format: '%a, %b %d %I:%M %p'
inclusions:
- title
# - link
exclusions:
- language
thats a custom component… did you do what i said to do? Update and try again?
I am having trouble getting this code to work. I copied and pasted it into my yaml file:
## Check Latest Mikrotik Firmware
- platform: feedparser
name: Engineering Feed
feed_url: 'https://mikrotik.com/download.rss'
date_format: '%a, %b %d %I:%M %p'
inclusions:
- title
- link
exclusions:
- language
- platform: template
sensors:
next_router_os_release:
value_template: >
{% set sorted_releases = states.sensor.engineering_feed.attributes | sort | reverse %}
{%- for release in sorted_releases if release | regex_match('.*\[Stable\].*') %}
{%- if loop.first %}
{{- release | replace('[Stable]','') }}
{%- endif %}
{%- endfor %}
I get the following output in Homeassistant:
I cannot figure out what the problem is. Can anyone assist?
Thanks,
Rick
The correct syntax for the line would be
{% set sorted_releases = state_attr('sensor.engineering_feed', 'entries') | sort(attribute='title') | reverse %}
but your sort isn’t doing anything worthwhile because you’re sorting a list of dictionaries.
but… if you’re just trying to get the latest release…
{% set keyword = '[Stable]' %}
{% set item = state_attr('sensor.engineering_feed', 'entries') | selectattr('title', 'search', keyword) | list | sort(attribute='title') | reverse | first %}
{{ item.title.replace(keyword, '') }}
Thank you for the reply. I put the code in and I am still getting unavailable. Here is how I formatted the new code…
## Check Latest Mikrotik Firmware
- platform: feedparser
name: Engineering Feed
feed_url: 'https://mikrotik.com/download.rss'
date_format: '%a, %b %d %I:%M %p'
inclusions:
- title
- link
exclusions:
- language
- platform: template
sensors:
next_router_os_release:
value_template: >
{% set keyword = '[Stable]' %}
{% set item = states_attr('sensor.engineering_feed', 'entries') | selectattr('title', 'search', keyword) | list | sort(attribute='title') | reverse | first %}
{{ item.title.replace(keyword, '') }}
Did I miss something?
Thanks,
Rick
are you getting errors?
I did not think to check the logs, sorry. I am getting an error.
- Template variable error: ‘states_attr’ is undefined when rendering ‘{% set keyword = ‘[Stable]’ %} {% set item = states_attr(‘sensor.engineering_feed’, ‘entries’) | selectattr(‘title’, ‘search’, keyword) | list | sort(attribute=‘title’) | reverse | first %} {{ item.title.replace(keyword, ‘’) }}’
I don’t know where to find a better in-depth guide to template syntax. The HA help pages only help me so much.
Rick
It’s state_attr
not states_attr
That correction got it working, thank you Burningstone. It is giving me a Development version though, and it appears to be the latest version, so the keyword piece is not formatted correctly.
Thanks,
Rick
I got it to work using the template editor in the developer tools. I removed the brackets from around the word Stable and put an * on the end of it. I tried putting an * in front of Stable also, but it gave an error.
Now the desired output is given. Not sure why this works though, just glad it does.
- platform: template
sensors:
next_router_os_release:
value_template: >
{% set keyword = 'Stable*' %}
{% set item = state_attr('sensor.engineering_feed', 'entries') | selectattr('title', 'search', keyword) | list | sort(attribute='title') | reverse | first %}
{{ item.title.replace(keyword, '') }}
Thanks everyone for the help.
Rick