Allow attributes as state
Closed this issue ยท 7 comments
Hi , Not sure it's actually possible, or my "Title" is wrong
But i just love your new "icon changes" with the state-value !
However i would love to be able to "fetch" the attribute "rssi" from domain/entity "device_tracker" ( As not all devices uses attribute-signal_strenght )
I can get "Domain: Device_tracker" in auto-entities, and sort by "rssi" , but it seems impossible to get a great look as your new icons for signal_strength
So basically my FR is something like above, if you understand ( Attaching a pic from my autoentities
Device_tracker is the only "component" which "expose" the same attributes for all WiFi-devices, i.e "signal_strength" ... rssi
BR , And Happy New Year :)
I don't use auto-entities card so I won't help you with it but all what you have there should be achievable with battery-state-card by itself.
The below listing is just an example which I think/hope should work (I haven't tested it). You would need to adjust the color/icon values
type: custom:battery-state-card
icon: "mdi:signal-cellular-{state|abs()|greaterthan(69,outline)|greaterthan(59,1)|greaterthan(49,2)|greaterthan(2,3)}"
valu_override: "{attributes.rssi}"
colors:
steps:
- value: 26
color: blue
- value: 36
color: green
- value: 45
color: yellow
- value: 60
color: red
sort:
by: state
desc: true
unit: dBm
filter:
include:
- name: entity_id
value: device_tracker.*
Yes i understand, it was wrong of me to show that "example", however your "suggestion" doesn't work, and i've tried a few others also , in Battery-state-card, with no luck , so my "bad" example, was just to explain (invisble) that it was the attribute-state, and not the entity-state that should be "addressable" !
The state of the battery is home/not_home, so it's the attribute "rssi" i need to get the "value" of, .. it either says NaN or Home/Not_home (latest with your example)
And there is No, colors of any kind
It take the "entities" with the "Signal_Strength" just fine, but all device_trackers shows "NaN", and are all grey
Below, is an "example" of the code im "playing with", as i wanted to use Battery-state-card for all my signal_strength/Rssi ( Wifi device ) ( That why my "request" was mend towards device_tracker-domain/attribute , as it uses rssi for all devices in the network
Left Column is with auto-ent- Right is bare Battery-state-card
type: horizontal-stack
cards:
- type: custom:auto-entities
card:
type: custom:battery-state-card
filter:
include:
- domain: device_tracker
options:
icon: "mdi:signal-cellular-{state|abs()|greaterthan(69,outline)|greaterthan(59,1)|greaterthan(49,2)|greaterthan(2,3)}"
valu_override: "{attributes.rssi}"
colors:
steps:
- value: 26
color: blue
- value: 36
color: green
- value: 45
color: yellow
- value: 60
color: red
unit: dBm
type: attribute
attribute: rssi
secondary_info: '{last_changed}'
exclude:
- state: unavailable
- state: not_home
- state: unknown
- group: group.wired_home
- attributes:
connection_type: wired
- attributes:
connection_type: disconnected
sort:
method: attribute
attribute: rssi
reverse: true
- type: custom:battery-state-card
secondary_info: '{last_changed}'
icon: >-
mdi:signal-cellular-{state|abs()|greaterthan(70,outline)|greaterthan(65,1)|greaterthan(50,2)|greaterthan(2,3)}
filter:
include:
- name: attributes.device_class
value: signal_strength
- name: entity_id
value: device_tracker.*
sort:
by: state
desc: true
bulk_rename:
- from: ' Signal'
- from: ' strength'
- from: ' Rssi'
- from: ' numeric'
value_override: '{state|abs()}'
colors:
steps:
- color: '#00ff00'
value: 50
- color: '#ffff00'
value: 65
- color: '#ff0000'
value: 100
gradient: true
view_layout:
grid-area: main1
And this is a copy/paste of your code
Ok there are few things:
- Dummy typo in my example: there should be "value_override" not "valu_override"
- Instead of using the "state" in
value_override
in your listing you should be using "attributes.rssi". This is the reason why the state shows up (Home/ Not at home" instead of RSSI - If the state is not being produced right you cannot expect the icons/colors to look right
- You cannot use both entity types in the filters as one has the value in the state and second one in the RSSI attribute. So one or the other wont be working
Please try the below listing
- type: custom:battery-state-card
secondary_info: '{last_changed}'
icon: >-
mdi:signal-cellular-{attributes.rssi|abs()|greaterthan(70,outline)|greaterthan(65,1)|greaterthan(50,2)|greaterthan(2,3)}
filter:
include:
- name: entity_id
value: device_tracker.*
sort:
by: state
desc: true
bulk_rename:
- from: ' Signal'
- from: ' strength'
- from: ' Rssi'
- from: ' numeric'
value_override: '{attributes.rssi|abs()}'
colors:
steps:
- color: '#00ff00'
value: 50
- color: '#ffff00'
value: 65
- color: '#ff0000'
value: 100
gradient: true
Finally ! Thx alot for your help , i've been struggling with these device_trackers, hope they eventually can become a "domain/among the new groups"
I have a group for the wired-device-trackers ( old style ) in yaml, no unique_id , but i couldn't figure out to exclude those
It got it working, however i couldn't figure out how to "exclude" the bunch i could with auto-entities, but it made me clean up in a bunch of "unknown, unavailable etc.", (even thou they were "disabled" they turned up here, same ofcause with all the Wired-Devices ( even thou they didn't have an attribute "rssi"
either, so i just added them all 12 to exclude
Maybe the value_override: '{attributes.rssi|abs()}' was the reason, as that was what the "statei" showed ( '{attributes.rssi|abs()}' ) :)
Now it looks great, just have to use the same colors-scheme as my Batteries, and maybe "play a little" with the icn change.
Im so pleased with this now ... was actually thinking about making template-sensors, from each device_trackers, as many integrations/devices don't show either rssi or signal_strength ... but then i saw your latest post ...and started cleaning up :)
If attribute is missing then it just prints the exact value which you have used in the value_override
.
To exclude such entities use the filter:
I wanted to suggest to use the exclude filter but I have realized that there is no option like "doesnt_exist" / "not_exists". I will create an issue to add it.
But you can do something else which may solve your problem. Instead of adding all device_trackers you can add only the entities which do have this attribute using the below filter:
filter:
include:
- name: attributes.rssi
This way you won't need to remove anything I hope
filter: include: - name: attributes.rssi
... yes it works, i had trying to "play" with that ( include device_trackers with attribute.rssi ! ) etc-, but thought that... "going through every entities" to find an attribute, would create "alot usage" larger than finding just the entity_id (device_tracker) .. well it does create A-lot usage ! ( i have 30 times more entities, and hundred times more attributes ) than , just entity_id: device_tracker* ( again, here comes my wishes in regards to "native groups, with unique_id", for device_trackers in HA )
And with your previous "example" , i ended up with 1 entity_id include ( device_trackers* ), and 12 entity_id exclude ( device_trackers.xxxx_xxx )
" not_exists " removed the 12 "wired" entities, And future "unwanted" bunch of "curious/bogus" "device_trackers !
Final Code:
type: custom:battery-state-card
icon: >-
mdi:signal-cellular-{attributes.rssi|abs()|greaterthan(70,outline)|greaterthan(65,1)|greaterthan(50,2)|greaterthan(2,3)}
filter:
include:
- name: entity_id
value: device_tracker.*
exclude:
- name: attributes.rssi
operator: not_exists
sort:
by: state
desc: true
value_override: '{attributes.rssi|abs()}'
colors:
steps:
- color: '#00ff00'
value: 50
- color: '#ffff00'
value: 65
- color: '#ff0000'
value: 100
gradient: true
well not "FINAL" , as i haven't got time to ajust colors/icons and "integrate" it in it's View-context
HAPPY NEW YEAR , To You To !