Switch with static energy usage

I am on a quest to visualize my energy usage.
I already have a bunch (~20) of energy meters, and they work like a charm, but there are also a few devices that do not give any energy measurements, but the energy usage is constant when “on” or “off” (like a light dimmer or even a simple light switch).

I mostly have Tuya devices. Regarding the energy meters, they only give Volt, Amps and Wattage. Not kWh.
Therefore, I did the following:

sensor:
  - platform: integration
    source: sensor.sw_bureau_kamer_wout_power
    name: verbruik_wout_bureau
    round: 2
    method: left

This gives me a Wh sensor that is visible in the energy dashboard.

BUT (and this is the question), I also have a light switch. I know that when the light is on, the usage is 18W and when it is off, the usage is 0W.
(actually it is a dimmer, and later on I will adjust the code for usage between 0-20% brightness, 21-40%, etc… But for now I want to keep it simple.)

So I made this sensor; when the light is on, I have a usage of 18W; when it is off 0W.

  - platform: template
    sensors:
      bureau_licht_power:
        unit_of_measurement: "W"
        value_template: >-
          {% if is_state('light.licht_bureau_light', 'on') %}
            18
          {% else %}
            0
          {% endif %}

Next, I did the same as with the energy meters

  - platform: integration
    source: sensor.bureau_licht_power
    name: verbruik_bureau_licht
    round: 2
    method: left

Now for the weird stuff.
When I look in the Developer tools, I see results. 18W / 0W and even the usage in Wh. But it does not show up in the energy dashboard. Not even on Year totals. What am I doing wrong. I have the feeling that I am making a dummy mistake :slight_smile:, but I cannot see it afer more than a week of searching.

Thank you for anyone that can help me!

There’s an easier way:

Hi tom_l, thank you for the extra info and I will certainly have a look at it.
I am still curious what I did wrong using the example above; if the error is something structural, it could give me issues later in other scripts.

To show up in the energy dashboard a sensor must have three attributes:

unit_of_measurement: kWh # or Wh, you have this one.
state_class: total_increasing # missing.
device_class: energy # missing.

You can’t add these attributes directly to the Riemann Sum integration options, so you have to use Customize.