Opacity from sun brightness

Good morning mates,
During creating my lights map, I am tring to set opacity value from a sunlight template sensor.
The idea is to have “darker” rooms in the evening, clear rooms during the day when the light state is off.

This is my card config:

type: picture-elements
title: Interrato
path: floorplan
panel: true
icon: mdi:floor-plan
image: /local/interratov3.png
elements:

  • type: image
    tap_action:
    action: toggle
    entity: switch.gruppo_luci_interrato
    image: /local/interratooff.png
    state_filter:
    ‘off’: opacity(60%)
    ‘on’: opacity(1%)
    style:
    top: 70.3%
    left: 20%
    width: 24.1%
    In this case, when the light is off I have 60% of opacity, when is on 1% of opacity of a black image (nterratooff.png)

My idea is to use the value of the sunlight sensor for off state filter opacity.
How may I use the variable?
My idea should be defining the variable

variables:

  • states[‘sensor.sunlight_pct’].state

And use like this in the image entity

state_filter:
‘off’: opacity({{ (state.sensor.sunlight_pct) }}%)

But I have only 100% opacity (or I think unmatched value)
Thank you lots,
Andrea

The picture elements card doesn’t specify that it supports templates, so therefore it probably doesn’t. You could possibly put this card on a Lovevlace Card Templater card to template “off”, which would then be called “off_template”. This doesn’t guarantee that the picture elements card will pick up dynamic changes though.

And btw you should surround your code in three backticks (```) so it formats correctly.

1 Like

I don’t think it can works…basically is applying a variable value as a css value…