Need to finetune trigger (and condition maybe), bot not sure how

Using this now, to see if my espresso machine is ready:

    trigger:
      platform: numeric_state
      entity_id: sensor.espresso_keuken_actueel
      above: 1250
      for:
        minutes: 10
    condition: []

thing is, the 10 minutes is not really correct, and sometimes it needs longer heating up before the machine goes in to ready mode, switching between heating and not heating frequently.

it takes between 10 to a few minutes more, before the machine is really in production state, so I am looking for a way to make this better.

in human language I’d say, it’s ready when having heated up for a longer period, it suddenly lowers the sensor.xxx_actueel and then starts using short intervals of heating (1250+) and not heating. (1.4).

The period of 10+ minutes heating is unique and only happens during startup. So I could also use that as a binary of sorts, and maybe enter that as condition? But then how to formulate the trigger…

maybe I need to use the frequently switching state, and record the shorter periods of heating and not heating, and use that as indication for being ready? But how…

to give you an idea of the switching frequency:


quite regular, but never exact… off for about a minute, on mostly between 10-15 seconds. need to be smart in the condition/trigger section :wink:
anyways, maybe you can help.
thanks for having a look!

You could try using a simple moving average filter sensor. You may have to play around with the window size but using it you should be able to numerically tell the difference between the initial on period (~2000W) and the pulsed “keep warm” period (~1200W average).

So the trigger would be something like this:

trigger:
  platform: numeric_state
  entity_id: sensor.filtered_power
  below: 1500

You would need some sort of condition to prevent triggering when home assistant starts.

just to be sure you read the above graph correctly: the large constant area of about 700 watts isn’t my espresso machine, its the base usage of the home…so you’d have to only take the spikes in to consideration.

AM I understanding you correctly the filter sensor could calculate an average usage and because that is higher during the warm up period than in the operational period, I can use the below: of that filter sensor as an indication for being ready? That would really be grand!

Ill create the sensor right away , though reading the docs, that isn’t as easy… need some reading up to do in these configuration options…

Yes. Essentially your espresso machine has a constant on period, then the thermostat controls the heat using pulse modulation. The filter turns this on/off signal into an average power value.

What-is-PWM-585x400

i see. very interesting, and sounds like exactly what I would need.

Could you help me to setup the sensor to start with for experimenting? what would, considering the description above would be the best setup to start with?

min temp would be 1.2 , because lower than 1 means it is out of water… max could be 1250. Timing periods I described already: at start about 10+ minutes on, after that cycling 1 min off, 10-15 secs on.

considering during hating up the average usage would be a constant 1250, the drop of the average to below that would indicate being ready?

now how to set that up in the filter, copying from the docs, I don’t have an idea how the reflect the actual needs in this…:

  - platform: filter
    name: "Espresso ready"
    entity_id: sensor.espresso_keuken_actueel
    filters:
      - filter: outlier
        window_size: 4
        radius: 4.0
      - filter: lowpass
        time_constant: 10
        precision: 2

I’ve also been contemplating a binary_sensor with a delay_on of the time between to powering periods.

      espresso_ready:
        friendly_name: 'Espresso ready'
        value_template: >
          {{ 1.2 < states('sensor.espresso_keuken_actueel')|float < 20 }}
        delay_on:
          seconds: 59

If that happens (the first time) the machine would be ready.

Start with this:

  - platform: filter
    name: "Espresso ready"
    entity_id: sensor.espresso_keuken_actueel
    filters:
      - filter: time_simple_moving_average
        window_size: '00:10:00' # time notation for the average window length

This will give about 10 espresso power switching events per window.

I suggest you give it a run and graph the results to see if it needs a longer or shorter window size. Longer window time will mean smoother average but slower to react.

I see, ok will do.

And then what about the triggering value for the automation? below 1000 would do? considering the first 10 + minutes it will be 1250+, and then starts switching, so averages below that?

You will have to test it and see.

will do, restarting as I type this.

added this to the above binary_sensor.espresso_ready to see what gives:

  - alias: 'Espresso ready'
    id: 'Espresso ready'
    trigger:
      platform: state
      entity_id: binary_sensor.espresso_ready
      to: 'on'
    condition:
      condition: template
      value_template: >
        {{not is_state('input_boolean.espresso_ready','on')}} # <-- first time check
    action:
      service: input_boolean.turn_on
      entity_id: input_boolean.espresso_ready

  - alias: 'Espresso ready off'
    id: 'Espresso ready off'
    trigger:
      platform: state
      entity_id: sensor.espresso_keuken_state
      to: 'off'
    condition: []
    action:
      service: input_boolean.turn_off
      entity_id: input_boolean.espresso_ready

exploring the options :wink:

if the filtered sensor proofs to work, that would really make my day, so thanks!

quick update:

binary_sensor seems to work fine, with the 2 automations to set the input_boolean (on which I can trigger other automations and notifications)

40
notice how the top boolean stays on, while the binary_sensor below is off. Which is exactly what I want, the boolean switches on, only after a first trigger. (testing for ‘on’ state, and simply only switching it off when the espresso machine itself is switched off, or runs out of water)

have an extra automation to switch off the boolean in case of water deficit (going below 1 watt)

the filter sensor is somewhat more difficult to understand, or I should say to use for the purpose I need it for mostly: signaling in the morning I can get out of bed because the espresso is ready :wink:

have a look at the history of it. which would resemble a mornings situation. How can this trigger an automation testing ready:

34

What is the length of time that history graph is displaying?

about 7 minutes I think

So it hasn’t gone through the 10 minute heating time yet.

Wait until it starts to go into the pulsed mode and see where that levels out.