Read value from counter entity for 3D Floorplan

Dear forum members,

I’m working on a 3D Floorplan for my Lovelace dashboard.
There are a lot of tutorials out there how to edit the raw Lovelace config and so on, but none of them explains how the code for modifying the CSS values on a light status change works.

For my WLED ARGB lamps, I can just use the given example as they are “smart” (they return a status → on/off and which color and brightness etc.)

opacity: >-
                  ${states['light.lamp1'].state === 'on' ?
                  (states['light.lamp1'].attributes.brightness / 255)
                  : '0'}

But now there is my problem: I modded a 2,4 GHz remote which was shipped with my two daylight led panels so that I can simulate a button press on it with my ESPHome Wemos D1 Mini and a few optocouplers.

Because another user told me I should try a template, I created a template light:

light:
  - platform: template
    lights:
      wandleuchten:
        friendly_name: "Wandleuchten"
        value_template: "{{ state_attr('counter.wand_counter', 'value')}}"
        turn_on:
          service: automation.trigger
          target:
            entity_id: automation.walllights_on
        turn_off:
          service: automation.trigger
          target:
            entity_id: automation.walllights_off  

The automations increase/reset the counter before the light switch will be toggled.
But when testing the lovelace card, the following happens:
Video

explanation: the two buttons on the left side (ON and OFF) directly toggle the switch.wandleuchte_on or switch.wandleuchte_off entity, so you can see when they turn yellow → their action is executed

Problem: The toggle in the light card turns itself off after a second without turning off the lights in reallife

EDIT: I fixed the problem by changing the value template as described below and adding the new entity to the entity list of the custom:config-template-card (This was missing in there so the Floorplan would only show the current state of the LED wall panels after a refresh and not “live”)

I’m sure there’s a problem in the ‘value template’ part of my code but I’m not good at templating so I thought someone out here could help me solve this :blush:

“value_template” mus return “on” or “off”.
You likely need something like:

        value_template: >-
          {% if state_attr('counter.wand_counter', 'value')|int > 0 %}
            on
          {% else %}
            off
          {% endif %}
1 Like

I fixed it by using

value_template: "{{ states('counter.wand_counter')|int > 0 }}"

Thanks!

1 Like

This may be an old topic but it save my day after a LOT of error messages that I wasn’t quite understanding. The documentation on the counter does not tell you at all how to read the value in a template, perhaps it could be updated with this?