Latest from YouTube Channel

Simulated Power Sensors in Home Assistant

November 9th, 2024
YouTube video

This is really quite surprising to me actually but one of the most requested things people contact me about is how I created all of the simulated power sensors in Home Assistant that I used to demonstrate the various power flow cards in a number of videos I made last year. Well, it’s actually really quite simple so I thought I’d put together this little tutorial to show you how.

So this is a multi step process. First we need to create a bunch of number helpers. These will be our controls. We can add them to our dashboard and move the sliders to adjust how much power we want to simulate for a given item. Those items might be your grid power, solar power, your car charger, that sort of thing. The problem with number helpers is that they are not power sensors, so even if you tell Home Assistant that the unit of measurement is Watts, it won’t behave like a power sensor so we have to then wrap the number helper in a template sensor. Let’s dive into Home Assistant and I’ll show you what I mean.

In Home Assistant, navigate to Settings > Devices & Services > Helpers (tab at the top). Click on the Create Helper button and scroll down the list to find ‘Number’ and select it. Create your helper with the following settings:

  • Name: Sim Power: Grid
  • Minimum value: -8000
  • Maximum value: 8000
  • Display mode: slider
  • Unit of measurement: W

Make a note of the entity ID – if you use the same settings I have it should be called input_number.sim_power_grid. Create another helper but this time choose the type of ‘Template’ from the list. You’ll be asked to choose between a binary sensor or just a sensor. Choose the latter, just ‘sensor’. Create your template sensor helper with the following settings:

  • Name: Sim Power: Grid
  • Template: {{ states(‘input_number.sim_power_grid’)|int(default=0) }}
  • Unit: W
  • Device Class: Power
  • State Class: Measurement

I suggest you now edit your dashboard and add an entities card containing both the input_number.sim_power_grid and the sensor.sim_power_grid entities to it. You can then test that everything works by adjusting the slider and ensuring both entity values change to the same thing at the same time.

If that worked then you can repeat the process for any other simulated power sensors that you require. For my example I’ll also be creating “Sim Power: Solar” and “Sim Power: Battery” sensors. When you have all of the sensors you need then you can start making use of them. One great way to visualise power is using a power flow card. My favourite of these is the Power Flow Card Plus which you can install in Home Assistant using HACS.

So this method isn’t just limited to power sensors. You can simulate all sorts of numeric sensors this way like battery charge percentages, temperature sensors, air quality, light levels, basically anything listed in the device class dropdown of the template sensor helper.

I use simulated sensors to test automations for all sorts of things in a controlled way without needing to wait for real sensors to give me the required values. If I’m writing an automation that will only run when it’s dark, I can test it during the day by feeding it a simulated sensor that I can control.

  • As an Amazon Associate I earn from qualifying purchases.