Closed slimcdk closed 2 years ago
Yes, please. Add the attributes also to the switch entities: I want to use with auto-entities the switches of monitor_docker in order to access the toggle functionality.
I've solved this by creating template sensors in HA that takes the sensor.docker_*_state as state and everything else I want/need as attributes.... It is a bit of effort, but it works very well!
Here is my config:
- platform: template
sensors:
docker_adguard_info:
friendly_name: AdGuard
value_template: "{{states('sensor.docker_adguard_state') | float | round(1)}}"
attribute_templates:
status: "{{states('sensor.docker_adguard_status')}}"
memory: "{{states('sensor.docker_adguard_memory') | float | round(1)}}"
memory_percent: "{{states('sensor.docker_adguard_memory_percent') | float | round(1)}}"
cpu: "{{states('sensor.docker_adguard_cpu') | float | round(2)}}"
network_speed_up: "{{states('sensor.docker_adguard_network_speed_up') | float | round(1)}}"
network_speed_down: "{{states('sensor.docker_adguard_network_speed_down') | float | round(1)}}"
network_total_up: "{{states('sensor.docker_adguard_network_total_up') | float | round(1)}}"
network_total_down: "{{states('sensor.docker_adguard_network_total_down') | float | round(1)}}"
uptime: >-
{% set up_time = (as_timestamp(now()) - as_timestamp(states.sensor.docker_adguard_up_time.state)) %}
{% set days = (up_time // (60 * 60 * 24)) | int %}
{% set weeks = (days // 7) | int %}
{% set hours = (up_time // (60 * 60)) | int %}
{% set hours = hours - days * 24 %}
{% set minutes = (up_time // 60) | int %}
{% set minutes = minutes - (days * 24 * 60) - (hours * 60) %}
{% set days = (days | int) - (weeks * 7) %}
{% macro phrase(value, name) %}
{%- set value = value | int %}
{%- set end = 's' if value > 1 else '' %}
{{- '{} {}{}'.format(value, name, end) if value | int > 0 else '' }}
{%- endmacro %}
{% set text = [ phrase(weeks, 'Week'), phrase(days, 'Day'), phrase(hours, 'Hour'),
phrase(minutes, 'Min') ] | select('!=','') | list | join(', ') %}
{% set last_comma = text.rfind(',') %}
{% set text = text[:last_comma] + ',' + text[last_comma +1:] %}
{{ text }}
You can define the sensors inside 1 sensor, yes it is not in the switch, I know that. The problem is to include it in the switch, means we need to add of code again. So I will close this ticket.
Make all data for a container accessible as attributes for every sensor. E.g every sensor as attributes on the switch.
This will make it significant easier to use auto generated entities such as auto-entities.
As of now it can't be done as e.g. auto-entities does not allow to substitute domains for entities and therefore you can't filter for switch. and reference belonging sensors.