Hi guys,
I have a Shelly 1pm controlling the charger for my plug-in hybrid vehicle. Sometimes I want it to start charging right away, and sometimes I want it to only start charging 2 hours after sunrise tomorrow to take maximum advantage of solar power generation.
I’ve wired a momentary action button to the switch input on the 1pm module, to be used to trigger the automation either in immediate or delayed mode.
The problem is that if I set the Shelly input to momentary action mode (so I can get single click or long click events), then the button also directly switches the Shelly relay on and off, which starts or interrupts a charge cycle right now irrespective of what I actually want.
If I set the Shelly input to detached switch, it leaves the charge cycle alone, but I can only get an On or Off state to use in my script.
To solve this, I am wanting to run a separate script to “read” how many times the 1pm switch input is triggered in a time period, and set a boolean helper to indicate what type of click event that should represent.
An automation will trigger two scripts when the button is pressed for the first time, then time delay long enough so it doesn’t interfere with the remainder of the “read” process.
Script 1 increments a number helper each time it sees the button being pressed and then loops around to look for another button press.
Script 2 times out over an “acceptable” time period (perhaps 3 seconds), then terminates script 1 and sets a boolean helper on the basis of the current value of the number helper, then resets the number helper and ends.
The Car Charge script will then be triggered by the change of state in the boolean helper - which is effectively simulating the click event that I can’t get out of the Shelly 1pm.
Trying to get the first script to do the read and loop cycle is what is holding me up right now - as I can’t save it due to errors being thrown around the repeat instruction.
Message malformed: extra keys not allowed @ data['sequence'][0]['target']['repeat']
The script starts with a counter increment to account for the button press that triggered the automation in the first place, then waits for the next “off to on” transition to increment again… etc
I picked 5 as a likely maximum count, as I can’t see any purpose for more than a quintuple press event
alias: car charge button
sequence:
- service: input_number.increment
target:
entity_id: input_number.car_charge_button
repeat:
- wait_for_trigger:
- platform: state
entity_id: binary_sensor.car_charger_input
to: 'on'
from: 'off'
- service: input_number.increment
target:
entity_id: input_number.car_charge_button
until:
- condition: state
entity_id: input_number.car_charge_button
state: 5
mode: single
I’ve tried to follow the example in the documentation - but clearly have gone wrong somewhere.
Where have I gone wrong?
Many thanks in anticiaption