The goal is to only turn the Tesla charger on, when the Solar PV array is outputting more than 6kW.
I want the trigger to be when the solar PV changes (which is every 10minutes) or just run manually every 5minutes.
Once its been turned on, due to generation being above 6, run a timer for 30minutes.
Thinking about this a little more , what if the car is flat and they want it charged irrespective of the power status - because they need to use the car! I suspect that if they manually charge it, the system will actually go and turn it off.
If in that 30minutes the solar drops below 6, then we want to cancel the timer and turn the charger off.
Does this seem correct?
var Timer Solar_Timer = null
val Integer Solar_TimeOut = 30
rule "Charge Tesla Model S, when Solar Production is above 6kWh"
when
Item SE_Live_Production changed or
Time cron "0 0/5 * * * ?""
then
if (SE_Live_Production.state > 6 | kW && TeslaCharge.state == "OFF")
if (Solar_Timer !== null) {
TeslaCharge.sendCommand("ON")
Solar.reschedule(now.plusMinutes(Solar_TimeOut))
} else {
TeslaCharge.sendCommand("ON")
Solar_Timer = createTimer(now.plusMinutes(Solar_TimeOut))
[ |
if (SE_Live_Production.state > 6 | kW) {
Solar_Timer.reschedule(now.plusMinutes(Solar_TimeOut))
} else {
TeslaCharge.sendCommand("OFF")
Solar_Timer = null
}
]
}
end
I regard cron triggered rules as a bit of bodge in most cases, and look for ways to have it all events-driven. Thatâs not always possible, but worth exploring.
We should take care here ⌠what if PV doesnât change, power maxed out or something?
Maybe the Item is still updated (to same). Would that be a better choice of rule trigger?
Perhaps it doesnât update at all sometimes - at night say - and you should indeed keep the cron.
Letâs guess you have defined somewhere else variables Solar_Timer and Solar_Timeout. I think just Solar here is a typo though.
Yes. Is this a problem to be tackled? Nowâs the time. Might have to come up with a way to detect âmanuallyâ and modify your automation. (Itâs useful to remember manual = not-auto, which can be easier to work out.) Or perhaps a way to detect âflatâ and modify.
Sort of related ⌠maybe youâve just left it out for clarity at this stage, but should you check the car is plugged in or something before turning charger on? If thatâs detectable, it is also perhaps useful as a trigger.
Because itâs going to turn it off again in a half hour. That might be thirty seconds after you really have plugged it in.
Iâm sure the charger will be idiot proof, but we donât have to behave like idiots to find out. Skimping on the logic leaves room for weird behaviour to creep in.
Yes, I will add a check to see if the charge port is open before charging. Thatâs all the binding can do I believe.
Kim, yeah Iâm thinking a switch which âARMSâ the rule is the go. Another way would be to use the Weather binding to check the weather, only run this rule if the weather for the day is not rainy or cloudy or something along those lines.
Does the rule seems logic correct?
var Timer Solar_Timer = null
val Integer Solar_TimeOut = 30
rule "Charge Tesla Model S, when Solar Production is above 6kWh"
when
Item SE_Live_Production changed or
Time cron "0 0/5 * * * ?""
then
if (SE_Live_Production.state > 6 | kW && TeslaCharge.state == "OFF")
if (Solar_Timer !== null) {
TeslaCharge.sendCommand("ON")
Solar_Timer.reschedule(now.plusMinutes(Solar_TimeOut))
} else {
TeslaCharge.sendCommand("ON")
Solar_Timer = createTimer(now.plusMinutes(Solar_TimeOut))
[ |
if (SE_Live_Production.state > 6 | kW) {
Solar_Timer.reschedule(now.plusMinutes(Solar_TimeOut))
} else {
TeslaCharge.sendCommand("OFF")
Solar_Timer = null
}
]
}
end
Do you have access to a state of charge measurement? Itâs not so difficult to modify behaviour to deal with flats, say not starting the off-timer until charge > 15%, and/or giving charge even if available solar below threshold.
var Timer Solar_Timer = null
val Integer Solar_TimeOut = 30
rule "Charge Tesla Model S, when Solar Production is above 6kWh"
when
Item SE_Live_Export received update or
Time cron "0 0/5 * * * ?"
then
var Number solar_power = SE_Live_Export.state as DecimalType
if (solar_power > 6.0 && TeslaCharge.state == OFF){
if (Solar_Timer !== null) {
TeslaCharge.sendCommand("ON")
Solar_Timer.reschedule(now.plusMinutes(Solar_TimeOut))
} else {
TeslaCharge.sendCommand("ON")
Solar_Timer = createTimer(now.plusMinutes(Solar_TimeOut))
[ |
if (SE_Live_Export.state > 6 | kW) {
Solar_Timer.reschedule(now.plusMinutes(Solar_TimeOut))
} else {
TeslaCharge.sendCommand("ON")
Solar_Timer = null
}
]
}
}
end