I am trying to get into the jinja2 templating for some sensors I would like to create.
I got hung up when I wanted to set a state for a binary sensor I created.
I am trying to create a binary_sensor that basically is true when there is an update for any of the HACS add-ons. I looked into a lot o the blueprints and automations that are out there, but I need something simpler for my dashboard.
I already have the HACS update, the Supervisor Update, etc. Need now the HACS Add-On update.
This is my development code:
{%- set dev = namespace() %} {%- set dev.name = '' %}
{%- set dev.update = '' %}
{%- for devid in (integration_entities('hacs') | map('device_id') | list) %}
{%- if state_attr('update.hacs_update', 'installed_version') != state_attr('update.hacs_update', 'latest_version') %}
set states('binary_sensor.hacs_addon_update') = True
{%- endif %}
{%- endfor %}
I need help in the set states('binary_sensor.hacs_addon_update') = True
How do I set a state for the binary_sensor in the code?
If I add {%, I get an error. (I am still working on when to use {% or {{, and other general syntax in jinja2)
There’s no service call to set a binary_sensor’s state. The integration that created the binary_sensor is responsible for maintaining its state.
There’s a python script posted elsewhere in the forum that can be used to force the binary_sensor’s state. However, this ‘forced’ value is temporary and doesn’t survive a restart (and is overwritten by the binary_sensor’s integration).
I suggest you design your template to report true/false and then use it in a Trigger-based Template Binary Sensor. Make its trigger either a Time Trigger or a Time Pattern Trigger, depending on how frequently you want to execute the template.
Used the wrong term, you are right. I am referring to updates for the Integrations and front end resources.
But I do not have the sensor.hacs in my system. Is this something that needs to be enabled somewhere?
That’s a legacy format template configuration which doesn’t support triggers. Refer to the documentation in the link I posted above.
If you can’t find the update sensor for HACS, it may simply be hidden. Go to Settings > Devices, click on HACS and check the Sensors section for hidden sensors.
And this is what I see when I go into the HACS device. I get the Update sensor, but this is for HACS I believe. I have a pending update for one of the integrations, so the sensor should be on at this moment:
Based on the feedback (thank you all), the path would be to create a template that outputs true or false, then a trigger to update the binary_sensor based on that.
I will post my code once I get it working today I hope.
Still not sure why I do not have the sensor.hacs which would solve all of this for me.
Neither. I put in the screenshots earlier. Can’t see any entities other than the update. entity. I am digging here now to try and figure it out vs my original intent which is nothing other than a workaround it seems