Trying to find cost of an appliance

Hello - I have a tuya based smart plug which I’ve managed to get onto localtuya. In the states under developer tools, I can see sensor.smartplug_wifi_1_power. It has a value of 36. However, I have tried to make a card with this, and it gives me “Entity not available: sensor.smartplug_wifi_1_energy”
My config yaml:
sensor:

  • platform: integration
    source: sensor.smartplug_wifi_1_power
    name: stereo_energy
    unit_prefix: k
    unit_time: h
    round: 2
    method: left

I am quite new to this and learning a lot, so if anyone can help, please keep in mind I’m a novice.

The entity names you are referring to are different. The one you say you can see is

sensor.smartplug_wifi_1_power

But the error message is saying you’re trying to use

sensor.smartplug_wifi_1_energy

So I change it to this?

sensor:

  • platform: integration
    source: sensor.smartplug_wifi_1_power
    name: smartplug_wifi_1_energy
    unit_prefix: k
    unit_time: h
    round: 2
    method: left

No, use the power sensor as you had it, but where did you get unit_time as an option? Remove that.

Did you restart after the changes? If it’s the first time you’re using a platform, you cannot only reload the config.

Then check your logs.

Also format your YAML as code. Structure is important.

yes I do restart each time.
I got the unit_time from chatgpt

It’s formatted differently in my config. I just can’t replicate it in this post…

Read the docs instead.

What do you mean? Can you not find the option? Click the cog and select the </> option or wrap your YAML in a pair of three backticks.

And please reply to my other point too: What’s in your log when you restart. It will tell you if there are problems.

My log doesn’t show anything regarding this device.

The cog in File Editor? The cog there doesn’t give me and option of </>

And the entity isn’t showing up under the state tab of your dev tools?

On the forum, when you create or edit posts.

It is a valid option, although h is the default so not needed in this case:

I think there’s a lot of confusion about what you’re trying to do in this thread. Your initial post indicated you just wanted to display the value of an entity in a card.

That entity, sensor.smartplug_wifi_1_power, is available.

All you then need is to add a card to your dashboard and then select that entity. As an example, the yaml for a sensor card on the dashboard will be like the below

graph: line
type: sensor
entity: sensor.smartplug_wifi_1_power
detail: 1

I’m not sure why you’re trying to configure things in your config.yaml to display a card. And please, do not use CHATGPT for this type of stuff, read the actual documents first.

Apologies for the confusion. I am trying to find how much an appliance costs to run. To do so, I have a smart plug which I believe I have working in Home Assistant. That’s the outcome, and I hope that is not confusing.
I’m not even sure what you are referring to when you say “read the actual documents first”. As I mentioned, I am new to this. Where are these documents? Presumably they will tell me how to set this up?

Thank you in advance.

Yes indeed it is showing under the state tab. It is reading a power of 36W and shows the following attributes…

state_class: measurement
unit_of_measurement: W
device_class: power
friendly_name: Smartplug wifi 1 Power

My yaml, formatted, reads

sensor:
  - platform: template
    sensors:
      stereo_amp_current:
        friendly_name: "Stereo Amp Current"
        unit_of_measurement: "mA"
        value_template: "{{ state_attr('switch.smart_wifi_switch_1', 'current') }}"
      stereo_amp_voltage:
        friendly_name: "Stereo Amp Voltage"
        unit_of_measurement: "V"
        value_template: "{{ state_attr('switch.smart_wifi_switch_1', 'voltage') }}"
      stereo_amp_power:
        friendly_name: "Stereo Amp Power"
        unit_of_measurement: "W"
        value_template: "{{ (state_attr('switch.smart_wifi_switch_1', 'current') | float / 1000) * state_attr('switch.smart_wifi_switch_1', 'voltage') | float }}"
      smartplug_wifi_1_power:
        friendly_name: "Smartplug WiFi 1 Power"
        unit_of_measurement: "W"
        value_template: "{{ (states('sensor.smartplug_wifi_1_current') | float / 1000) * states('sensor.smartplug_wifi_1_voltage') | float }}"
      smartplug_wifi_1_energy_calc:
        friendly_name: "Smartplug WiFi 1 Energy Calculated"
        unit_of_measurement: "kWh"
        value_template: >
          {% set power = states('sensor.smartplug_wifi_1_power') | float %}
          {% set last_updated = states.sensor.smartplug_wifi_1_power.last_updated %}
          {% set hours_since_update = ((now() - last_updated).total_seconds() / 3600) | float %}
          {{ (power * hours_since_update / 1000) | round(3) }}
     
     

sensor:
  - platform: integration
    source: sensor.smartplug_wifi_1_power
    name: stereo_energy
    unit_prefix: k
    round: 2
    method: left


  - sensor:
      - name: "Smartplug WiFi 1 Cost"
        unique_id: smartplug_wifi_1_cost
        unit_of_measurement: "AUD"
        state: >
          {% set time = now().time() %}
          {% set energy = states('sensor.smartplug_wifi_1_energy') | float(0) %}
          {% if (time >= '05:00:00' and time < '07:00:00') or (time >= '21:00:00' and time < '00:00:00') %}
            {{ (energy * states('input_number.peak_rate') | float) | round(2) }}
          {% elif (time >= '07:00:00' and time < '09:00:00') or (time >= '17:00:00' and time < '20:00:00') %}
            {{ (energy * states('input_number.shoulder_rate') | float) | round(2) }}
          {% else %}
            {{ (energy * states('input_number.off_peak_rate') | float) | round(2) }}
          {% endif %}

input_number:
  peak_rate:
    name: Peak Rate
    initial: 0.3783
    min: 0
    max: 1
    step: 0.0001
  off_peak_rate:
    name: Off Peak Rate
    initial: 0.2377
    min: 0
    max: 1
    step: 0.0001
  shoulder_rate:
    name: Shoulder Rate
    initial: 0.3556
    min: 0
    max: 1
    step: 0.0001

Believe me, I find this incredibly frustrating, so I apologise if you too are frustrated by this simple line of questioning. Thank you for your formatting help.

You precopsuly wrote:

But your config says:

The one integrating to energy is:

You don’t need both and make sure to use the one you intend. I don’t see sensor.smartplug_wifi_1_energy defined anywhere.

I meant the energy sensor, not the power sensor.

Try a Utility Meter - Home Assistant instead.