I now want to add another picture for when state is not ‘home’ or ‘not_home’, because the entity now supports zoning. If thats the case Ive added a w_zoning.png and need to template that here
- entity: device_tracker.w_presence
style_template: >
if (state in ['home','not_home']) return 'background-image: url(\"/local/tiles/family/w_' + state + '.png\")';
return 'background-image: url(\"/local/tiles/family/w_' + 'zoning' + '.png\")';
I cant seem to get the correct template syntax for that.
if (state === 'home' or 'not_home')
if (state === 'home') or (state === 'not_home')
if (state in ['home','not_home'])
none of these work
even tried:
if (state === 'home') return 'background-image: url(\"/local/tiles/family/m_' + state + '.png\")';
if (state === 'not_home') return 'background-image: url(\"/local/tiles/family/m_' + state + '.png\")';
return 'background-image: url(\"/local/tiles/family/m_' + 'zoning' + '.png\")';
yes indeed, that’s what the current setup does. Since the templates in Tiles work different from the regular templates it always is a bit of a search to find the correct format. Apparently this works now, but I cant help wondering if the template could be optimized.
Next step is testing if I can get the Tiles images to follow the state of a changed device_tracker setup. Ill test using the life360 components device_tracker and see if it willl follow the zones directly. So, not just say Zoning and show a default zoning image (which is what is does now) but truly show an overlay image of the active zone.
ha, thats very smart indeed! never thought of that, and always found a way to template in the Tiles setup itself… duh.
only thing I missed in the option of tiles was a direct image_template, and this might indeed be away to mitigate that.
Since life360 component has the home, not_home and zones as its state, Ill try that first, simply by using:
return 'background-image: url(\"/local/tiles/family/m_' + state + '.png\")';
though I might have to be forced using an expanded setup because of my wish to display different background-color too when zoning (and not be able to use the global ‘on’ and ‘off’ colors:
if (state === 'home') return 'background-image: url(\"/local/tiles/family/m_' + state + '.png\")';
if (state === 'not_home') return 'background-image: url(\"/local/tiles/family/m_' + state + '.png\")';
return 'background-color: #643aac;background-image: url(\"/local/tiles/family/m_' + 'state' + '.png\")';
so 3 lines necessary, simply because I need a third background color if state !== ['home','not_home']
there is no state ‘zoning’ that’s exactly the challenge… the device is zoning, when it isnt home or not_home…
btw please have a look with me at this, if I finally make it to the zoning images…pff
some of these Zones of Life360 are like this" ‘Multiple Words’. Eg multiple capitalized words , and no _ to connect them. Ive tried to make image files like that to fit the template + state + .
so I tried m_Multiple Words.png .Which doesnt work obviously. Need to reformat the ‘+state+’ to change that. would this do it: + state|lower|replace(" ", "_") + ?
btw2: there is an attribute ‘Moving’: which is set to true/false, so I might be able to test on that! in stead of if (state === ‘zoning’), would if (attributes.moving === 'true') work? Or should I use some other syntax for evaluating an attribute here?
+ state{{replace(' ','_')| lower }} + ?
or this maybe: {{state|replace(' ','_')| lower }}
well yes, they are defined in the zones setup of HA. I could easily change that to be lower case and not use a space, but then they would show terribly in the frontend…