However that won’t solve the problem either because a switch is a device that is either on or off. you are trying to count how many lights are on. For that you need a sensor.
so change “switches:” to “sensor:”
also you didn’t indent the “unit_of_measurement” and everything below it far enough.
BUT…
if you already have a “sensor:” entry in your configuration.yaml then you can add that because it will only allow one “sensor:” entry in that location.
If that’s the case the just add the template portion under the existing “sensor:” entry like:
also realize you are using the legacy template sensor syntax instead of the modern template syntax. It’s not really a big deal as both still work but someone I’m sure will come along telling you to change it to the other syntax so I figured I’d beat them to the punch.
lastly you should not post screen shots of the code. please use code blocks by copying the text and using three backticks on the line before and after the text. It allows others to just copy your code and edit it as needed without having to write it all out from scratch.