How to get value from HABPanel slider in script?

TL;DR:
How to get value from HABPanel slider in script?

Long version:

I have working set of rules that control a pump depending on available power. The pump is expected to work 8h per day. Currently it’s a fixed value in the script:

var pool_pump_run_time = items.Pool_Pump_Run_Time;
var pool_pump_daily_run_limit = Quantity("8 h");

// Check is Pool Pumps runs longer than the limit...
if (pool_pump_daily_run_limit.lessThanOrEqual(pool_pump_run_time)) {
  // ... and if Pool Pump is enabled
  if (items.Enable_Pool_Pump.state.toString() == "ON") {
    console.log("Pool Pump daily run time ", pool_pump_run_time.quantityState.toUnit('h'), " over the limit ", pool_pump_daily_run_limit, ". Disabling Pool Pump....");
    items.Enable_Pool_Pump.sendCommand("OFF");
  }
}

I added a slider to one HABPanel
image
I can’t figure out how to get the value in my rule. I searched the forum - multiple solutions, but nothing that I could implement with my current knowledge level. Any ideas?

You just need to have the slider connected to an item. Then your script can also reference the value of that item’s state.

1 Like

Thank you!!! It’s so easy, when you know how to do it…

var pool_pump_run_time = items.Pool_Pump_Run_Time;
var pool_pump_daily_run_limit = items.pool_pump_run_time_setpoint.quantityState.toUnit('h');

// Check is Pool Pumps runs longer than the limit...
if (pool_pump_daily_run_limit.lessThanOrEqual(pool_pump_run_time)) {
  // ... and if Pool Pump is enabled
  if (items.Enable_Pool_Pump.state.toString() == "ON") {
    console.log("Pool Pump daily run time ", pool_pump_run_time.quantityState.toUnit('h'), " over the limit ", pool_pump_daily_run_limit, ". Disabling Pool Pump....");
    items.Enable_Pool_Pump.sendCommand("OFF");
  }
}

1 Like