template:
- sensor:
- name: My Device Power
device_class: power
state_class: measurement
unit_of_measurement: W # or kW
state: "{{ 42 if is_state('switch.my_switch','on') else 0 }}"
There’s also this that may be easier if you have a lot of these to do: