Using power consumption to show information (status, elapsed time, count) of cycles on a dish washer

Hi!

I’m guessing that the answer to my questions is “template sensor”, but I need some help in getting started…

I have a “dumb” dish washer mounted on a smart socket, allowing me to see power consumption etc in Home Assistant. I want to use this information to generate new sensors, making my dishwasher somewhat smarter. Based on power consumption data, I would like to have the following new sensors:

  • One that count the number of cycles (to keep track of the number of cycles during a month)
  • One that shows a status of the cycle (e.g. Inactive, Wash ongoing, Complete)
  • One that shows elapsed time (e.g. 01:20 since going from “inactive” to “wash ongoing”)

Power consumption through a cycle would normally look like this:

I’m guessing the three highs are heating up water, and in between just circulating the water in the dish washer. My dish washer opens up automatically at the end, and it is possible that a fan is active in the end to try to dry up all the wash, hence the “End” should perhaps be at 02:05 instead of 01:20.

Similarly, I have a smart socket on my tumble dryer, where I would love to do the same. A cycle here would normally look like this:


The same request here, but a bit different power consumption through the cycle. From “End” and until zero consumption, the tumbler plays a (annoying…) sound indicating that the cycle is finalized.

Appreciate all help - as well as ideas or other tips related to this topic!

Best regards,
Pjotr (Norway)

3 Likes

I’ve created a (binary)sensor that turns on when my powermeter detects a usage of more than 2 Watts for more that 2 minutes and turns off if it has been below 2 Watts after 6 minutes:
image

- platform: template
  sensors:
    washer_status:
      friendly_name: "Wasmachine"
      delay_on:
        minutes: 2
      delay_off:
        minutes: 6
      value_template: >-
#        {{ states('sensor_to_monitor')|float > value_before_trigger_on }}
        {{ states('sensor.zolder_wasmachine_energy_power') | float(0) > 2 }}

Because I also wanted to see the time it was running I’ve created another sensor that tells the time it has been running:

- platform: template
  sensors:
    wasmachine_looptijd:
      friendly_name: Looptijd wasmachine
      value_template: >
        {% set x = states('sensor.time') %}
        {% set t = 0 if states('binary_sensor.washer_status') == 'off' else now().timestamp() - states.binary_sensor.washer_status.last_changed.timestamp() %}
        {{ t | timestamp_custom('%H:%M', false) }}

To top it al of I’ve also made an automation that’ll inform me through my Nest speakers and telegram what device has been started/stopped:

alias: Melding - Apparatuur in-/uitgeschakeld
description: ''
trigger:
  - platform: state
    entity_id:
      - binary_sensor.washer_status
      - binary_sensor.dryer_status
      - binary_sensor.dishwasher_status
    id: Apparatuur in-/uitgeschakeld
condition: []
action:
  - service: tts.cloud_say
    data_template:
      entity_id: media_player.woonkamer
      message: >-
        De {{trigger.to_state.name}} is zojuist gestart of heeft zojuist zijn
        programma afgerond.
  - service: notify.telegram
    data:
      message: >-
        De {{trigger.to_state.name}} is zojuist gestart of heeft zojuist zijn
        programma afgerond.
mode: single

The last one is a work in progress because I would like it to say if a device has been started or stopped.

Since I’m going to pay top dollar for my electricity in a couple of weeks I’ve made an automation for my dishwasher, turning the dishwasher off and restarting it when I’m in the lower tarrifs. It’s a bit off-topic, but it might interest you. I’ve made the assumption that if I turn on the dishwasher before 6PM it was done on purpose.

alias: Schakeling - Vaatwasser
description: ''
trigger:
  - platform: numeric_state
    entity_id: sensor.keuken_vaatwasser_energy_power
    above: '60'
    id: Vaatwasser stroomverbruik
  - platform: time
    at: '23:10:00'
    id: Vaatwasser inschakelen
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: Vaatwasser stroomverbruik
          - condition: time
            after: '18:30:00'
            before: '23:00:00'
        sequence:
          - type: turn_off
            device_id: XXXXXXXXXXXX
            entity_id: switch.keuken_vaatwasser
            domain: switch
          - service: media_player.volume_set
            data:
              volume_level: 0.6
            target:
              entity_id: media_player.woonkamer
          - service: tts.cloud_say
            data:
              entity_id: media_player.woonkamer
              message: >-
                De vaatwasser wordt nu uitgeschakeld en zal om tien over elf
                weer worden ingeschakeld.
      - conditions:
          - condition: trigger
            id: Vaatwasser inschakelen
        sequence:
          - type: turn_on
            device_id: XXXXXXXXXXXX
            entity_id: switch.keuken_vaatwasser
            domain: switch
    default: []
mode: single

I’ve used a powerplug from Moeshouse that was ESP8266-based (JH-G01E). Unfortunately their latest sockets come with Tuya hardware and can’t be flashed with Tasmota. It where nice plugs to measure power, switch off devices, etc.

6 Likes

Thank you so much, Christiaan! :slight_smile:

I will try this out.

1 Like

I’ve tried everything to get this working. Has the ‘template:’ coding changed?

It is still working with my version of HA, and I update whenever there is an update.
You could post your configuration, etc. and hope the community can help.

Invalid config for [sensor.template]: [delay_on] is an invalid option for [sensor.template]. Check: sensor.template->sensors->washer_status->delay_on. (See ?, line ?).

  - platform: template
    `sensors:
      washer_status:
        friendly_name: "Washing Machine"
        delay_on:
          minutes: 2
        delay_off:
          minutes: 6
        value_template: >-
          {{ states('sensor.washing_machine_2')|float > 2 }}

Is it this ?

  - platform: template
    sensors:
      washer_status:
        friendly_name: "Washing Machine"
        delay_on:
          minutes: 2
        delay_off:
          minutes: 6
        value_template: >-
          {{ states('sensor.washing_machine_2')|float > 2 }}

@ChrisHA This should be a binary sensor template. You will get this error if you put it as a regular sensor template

Sorry, it’s indeed a binary sensor. Thanks for pointing that out, I’ve edited my reply.

Hi all! I’m trying to implement binary sensor code but while in developer tool → templates it returns True or False but the status of the binary sensor is always Unknown in state… This is my code:

binary_sensor:
  - platform: template
    sensors:
      washer_status:
        friendly_name: "Washing Machine"
        delay_on:
          minutes: 2
        delay_off:
          minutes: 6
        value_template: >-
          {{ states('sensor.shelly_shsw_pm_d8bfc019bffb_current_consumption') > 5 }}

With this response I have learned how custom sensors works, thanks so much!

1 Like

Just in case anyone had the same issue as me… i had to change the following:

{% set t = 0 if states('binary_sensor.washer_status') == 'off' ...

to:

{% set t = 0 if states('binary_sensor.washer_status.state') == 'off' ...

(to include state property of the binary sensor, otherwise it evaluates the whole object)

When I run {{ states(‘binary_sensor.washer_status.state’) }} in developer tools it outputs unknown, as for when I run {{ states(‘binary_sensor.washer_status’) }} it either returns on or off.

If it works for you then keep it, but it looks like a combination of two methods described in the Templating - Home Assistant (home-assistant.io) doc:

{{ states('device_tracker.paulus') }}
{{ states.device_tracker.paulus.state }}

hmm interesting… i wonder if it’s a difference with the integrations perhaps? For me the non-state version returns a whole object.

Just out of interest, did you mention you were counting the number of times per month/day that the washer was active? I’m keen to put that in place, but not sure what to use?

I’m not counting when an appliance is active, although you’ve planted a nice idea for the future😀 It could be something like a utility meter that resets weekly and is triggered by the time the appliance is turned on.

1 Like

Wow, genius! This is exactly what I try to accomplish, but I am totally stuck. Also I must admit I’m not skilled at all, in creating codes, scripts etc… I have the template sensor parts in my .YAML atleast.

I have a central wood boiler, which I would like to measure in some different ways for statistics and supervision. I want to know:

-If it’s burning, and for how long. If it have stopped, how long did it burn?
-How long has it been since the last fire burned out?
-Approximate amount of total wood consumed since last (manual) reset. One fire consumes about 130 litres of wood
-Total number number of fires since last (manual) reset.

I try to grasp your code and see if I could use it, and how to implement it, any help would be greatly appreciated!

All of the info I want to gather should be able to come from the smart plug I use to power it. It measures power consumption, and I know that if the boiler pulls 8-12W, it’s idle = no fire. When the internal fan starts, it pulls about 400W, then settles for around 200W until the wood is consumed and the fan switches off and the boiler pulls 8-12W again until next time I start a new fire.

Sometimes I start the fan while cleaning the boiler though, so ideally, the counters I want should not start until power have been > 100W for say 15 minutes.

Using your nice design in the UI, it should look something like this:

4c2a623c22ac734afa1a85db43eda7c456b19d0a

My sensor for tracking power usage is named sensor.power_127

I would be super grateful if anyone could help me get started with some code! :grinning:

I have atleast managed to create an automation for a counter that tracks how many fires that have been made. The code looks like this:

  alias: Vedpanna räknare
  description: ''
  trigger:
  - type: power
    platform: device
    device_id: 929394f7c6878c0d3509d5e89a6c241b
    entity_id: sensor.power_127
    domain: sensor
    above: 100
    below: 600
  condition: []
  action:
  - service: counter.increment
    data: {}
    target:
      entity_id: counter.elpatron
  mode: single

In the UI it looks like this:

1 Like

Ok, the counter in the post above did NOT work :grinning_face_with_smiling_eyes:

I just lit a fire and it keeps increasing for some reason… I will have to try harder.

I still consider myself a noob, but hopefully this will get you in the right direction.
You could create the following binary sensor, it’ll change state to ‘on’ when it uses 100 watts and has being doing so for 15 minutes, in its ‘on’ state the icon is fire and in its ‘off’ state its fire-off:

- platform: template
  sensors:
    vedpanne_status:
      friendly_name: "Vedpanne status"
      delay_on:
        minutes: 15
      delay_off:
        minutes: 6
      value_template: >-
       {{ states('sensor.power_127') | float(0)> 100 }}
      icon_template: >
          {% if is_state('binary_sensor.vedpanne_status','on') %} 
          mdi:fire
          {% else %} 
          mdi:fire-off
          {% endif %}

The following sensor will show you how long the sensor is in the ‘on’ state:

- platform: template
  sensors:
    vedpanne_varaktighet:
      friendly_name: "Vedpanne varaktighet"
      value_template: >
        {% set x = states('sensor.time') %}
        {% set t = 0 if states('binary_sensor.vedpanne_status') == 'off' else now().timestamp() - states.binary_sensor.vedpanne_status.last_changed.timestamp() %}
        {{ t | timestamp_custom('%H:%M', false) }}

The time till last fire is an “inverted” vedpanne_varaktighet sensor, this will show the time since the last ‘off’ state of the vedpanne_status:

- platform: template
  sensors:
    vedpanne_varaktighet_tid:
      friendly_name: "Vedpanne varaktighet tid"
      value_template: >
        {% set x = states('sensor.time') %}
        {% set t = 0 if states('binary_sensor.vedpanne_status') == 'on' else now().timestamp() - states.binary_sensor.vedpanne_status.last_changed.timestamp() %}
        {{ t | timestamp_custom('%H:%M', false) }}

The following I haven’t tested, but it should display the number of fires over a 24-hour period:
(inspired by Count how many times a sensor crossed a threshold in a period - #3 by lujmoarf)

sensor:
  - platform: history_stats
    name: vedpanne_antal_brander
    entity_id: binary_sensor.vedpanne_status
    state: "on"
    type: counts
    end: "{{ now() }}"
    duration:
      hours: 24

For the consumed wood, there is a lot of possibilities, the following should give you the amount of time the burner was burning, you could use that number to calculate te amount of wood burned (I have created sensors that multiply values from one sensor with another one, but I have not yet multiplied time with a “fixed” value):

sensor:
  - platform: history_stats
    name: vedpanne_ved_brandes
    entity_id: binary_sensor.vedpanne_status
    state: "on"
    type: ratio
    end: "{{ now() }}"
    duration:
      hours: 24
1 Like

Thank you very much for this! You have no idea how helpful this is! I will tinker with these codes and see what I can make with it!