Light status from another sensor

Hi,
I have a light that i can control it via normal wall switch and also with an relay because they are connected as two-way switch.
Now i have a current transformer sensor that tells me if the light is on or off and based on this sensor value i want to set the on or off image

This is what i have so far…

  - entity: light.living
    value_template: >-
      {% if value.current_check >= 1 %}}
        image: /local/living.JPG
      {%else%}
        image: /local/living_off.JPG    
    tap_action:
      action: toggle
    type: picture-entity   

Thanks

None of this follows home assistant & yaml rules.

  1. (HomeAssistant rule) - You’re adding a key that is invalid for an entity in lovelace. value_template is not listed in the documents, therefore it is not valid.
  2. (HomeAssistant rule) - Templating isn’t available anywhere in lovelace currently. You have to do all templating in home assistant, not lovelace.
  3. (Yaml rule) - You can’t have a jinja template span multiple fields. Templates can only be in 1 field. I.e. the value template field. You cannot add a field name and expect it to work.

So with that being said, what you’ll need is a custom lovelace card that allows templating in any yaml field.

I recommend getting HACS (Home assistant community store) for your install, then look for the config template card. https://github.com/custom-cards/config-template-card

Then… your yaml will look something like this:

type: 'custom:config-template-card'
variables:
  - states['sensor.light_level'].state
entities:
  - sensor.light_level
card:
  type: entities
  entities:
  - entity: light.living
    icon: "${vars[0] >= 1 ? '/local/living.JPG' : '/local/living_off.JPG'}"
    tap_action:
      action: toggle
    type: picture-entity  

Thanks Petro for detailed answer.
I have installed HACS and config-template-card but i still get this error message:


Am i missing something ?

Thanks.

did you add the card to your resources?

yes. Like this.

resources:
  - url: /community_plugin/config-template-card/config-template-card.js
    type: module

Your url isn’t correct. Just follow the instructions and you should be good to go. Or install HACS as @petro suggested.

I have installed HACS, that url is generated by HACS. See img bellow:


If the url is incorrect i should get **Custom element doesn't exist**, but i get **No type configured**

Yeah, I see I was wrong on this.

it’s possible that the UI does not support this nested card type.

@petro what do you mean by “UI does not support nested card type” ?
On the plugin github page doesn’t say anything about supported/unsupported version .

Still didn’t figure it out a way to update the light state based on another sensor value.
Any hint will be great.

Thanks

The UI editor doesn’t support everything that is possible using only yaml. That is what I’m refering to. It’s possible that the UI config checker doesn’t support a card inside a card (nested). I don’t know because I use yaml mode. This has nothing to do with individual cards or the plugin itself.

I literally wrote the code out for you. You have an example.

I’ve switch also to yaml mode and i got same error: “No type configured”

Am i doing something wrong ?

You must be. Verify that the plugin exists at the location you are using for the resource.

You have to reference the entities card type as “custom:hui-entities-card”.

From the README.md:
Note: All templates must be enclosed by ${} and card type must custom even for core. e.g. custom:hui-shopping-list-card

1 Like