Dynamic IR AC control script using power monitoring?

I have a Broadlink IR blaster controlling a dumb AC that is connected to a Shelly Plug for power monitoring. The AC uses the same code for on or off.
I’ve created scripts for each button control and I’m trying to make “smart” on/off scripts using the power monitoring.

So far, my script is failing at the condition of power states of the Shelly plug. Removing the condition allows the script to run. I’ve verified that the plug is providing state values and even successfully tested the condition in a test automation.
Should I be using an input boolean for scripts? Configuring a helper toggle just gives me a switch, doesn’t seem like I can configure its state based on sensor state.

What I’m trying to do:
Turn off with missed command protection:
-If: power is above 20w
-Then: run ‘turn off’ script
-Then: delay 1 minute
-If: power is above 20w
-Then: run ‘turn off’ script

Actual yaml for turn off script as an example:

alias: Bebe AC turn off
sequence:
  - &ref_0
    type: is_power
    condition: device
    device_id: [actual ID] 
    entity_id: sensor.plug_bebe_ac_power
    domain: sensor
    below: 0
    above: 20
  - &ref_1
    service: script.ac_off
  - delay:
      hours: 0
      minutes: 1
      seconds: 0
      milliseconds: 0
  - *ref_0
  - *ref_1
mode: single
icon: mdi:power-off

I just implemented SmartIR today, and noted it does support a power monitor (as well as a temperature sensor), both are optional, but i am seriously considering a power monitor, as the dumb ac has no feedback, so i would ever know if it is really off🤨

GitHub - smartHomeHub/SmartIR: Integration for Home Assistant to control climate, TV and fan devices v allows me to kindah make it smart :wink:

That’s pretty interesting. Looking at it, it would require a binary state (on/off) for power. I think that would make scripting easier as well, so does an input boolean helper provide that from a numeric sensor value?

it is very easy to create a boolean sensor from an analog sensor using a template :wink:

Here’s an example from my SmartIR setup for a gas heater:

binary_sensor:
  - platform: template
    sensors:
      lounge_gas_heater_power:
        friendly_name: "Lounge Gas Heater Power"
        device_class: "power"
        value_template: "{{ states('sensor.gas_heater_plug_power')  | float > 20 }}"

Which turns the binary_sensor on if the power usage from the plug goes above 20W, off when below 20W

1 Like

Alright, looks my time has come. No more hiding behind the UI. I’ll try to figure out the template and report back.

You will only need to change the entity id for your power sensor and the power value relative to your situation.

Thanks @sparkydave, i was just about to post the template docs and some examples….now i don’t have to :+1:t4: