Experimental power mode for standard actor

Power = 100: standard on
Standard sampling time is 5 seconds.
if power is set to 50%, heating time is 2.5 sec and witing time (gpio off) is also 2.5 sec
Changing power to lower readings, wil reduce heating time within the 5 seconeds and increase waiting time
Increase of power results in longer heating times and reduced wait times
Sort of a poos men's PWM with a fix requency of 0.2 hz

This will reduce the complexity of all PID plugins.

Some additional tests and changes might be required for api.
This commit is contained in:
avollkopf 2021-11-08 19:01:53 +01:00
parent 5b0f351a98
commit 40121e667e

View file

@ -27,15 +27,15 @@ if (mode == None):
@parameters([Property.Select(label="GPIO", options=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27]), Property.Select(label="Inverted", options=["Yes", "No"],description="No: Active on high; Yes: Active on low")]) @parameters([Property.Select(label="GPIO", options=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27]), Property.Select(label="Inverted", options=["Yes", "No"],description="No: Active on high; Yes: Active on low")])
class GPIOActor(CBPiActor): class GPIOActor(CBPiActor):
@action(key="Cusotm Action", parameters=[Property.Number("Value", configurable=True), Property.Kettle("Kettle")]) # Custom property which can be configured by the user
async def custom_action(self, **kwargs): @action("Set Power", parameters=[Property.Number(label="Power", configurable=True,description="Power Setting [0-100]")])
print("ACTION", kwargs) async def setpower(self,Power = 100 ,**kwargs):
self.power=int(Power)
if self.power < 0:
@action(key="Cusotm Action2", parameters=[Property.Number("Value", configurable=True)]) self.power = 0
async def custom_action2(self, **kwargs): if self.power > 100:
print("ACTION2") self.power = 100
await self.set_power(self.power)
def get_GPIO_state(self, state): def get_GPIO_state(self, state):
# ON # ON
@ -46,6 +46,7 @@ class GPIOActor(CBPiActor):
return 0 if self.inverted == False else 1 return 0 if self.inverted == False else 1
async def on_start(self): async def on_start(self):
self.sampleTime = 5
self.power = 100 self.power = 100
self.gpio = self.props.GPIO self.gpio = self.props.GPIO
self.inverted = True if self.props.get("Inverted", "No") == "Yes" else False self.inverted = True if self.props.get("Inverted", "No") == "Yes" else False
@ -54,6 +55,9 @@ class GPIOActor(CBPiActor):
self.state = False self.state = False
async def on(self, power = None): async def on(self, power = None):
if power is not None:
self.power = power
logger.info("ACTOR %s ON - GPIO %s " % (self.id, self.gpio)) logger.info("ACTOR %s ON - GPIO %s " % (self.id, self.gpio))
GPIO.output(self.gpio, self.get_GPIO_state(1)) GPIO.output(self.gpio, self.get_GPIO_state(1))
self.state = True self.state = True
@ -68,7 +72,24 @@ class GPIOActor(CBPiActor):
async def run(self): async def run(self):
while self.running == True: while self.running == True:
await asyncio.sleep(1) if self.state == True:
heating_time=self.sampleTime * (self.power / 100)
wait_time=self.sampleTime - heating_time
if heating_time > 0:
#logging.info("Heating Time: {}".format(heating_time))
GPIO.output(self.gpio, self.get_GPIO_state(1))
await asyncio.sleep(heating_time)
if wait_time > 0:
#logging.info("Wait Time: {}".format(wait_time))
GPIO.output(self.gpio, self.get_GPIO_state(0))
await asyncio.sleep(wait_time)
else:
await asyncio.sleep(1)
async def set_power(self, power):
self.power = power
await self.cbpi.actor.set_power(self.id,power)
pass
@parameters([Property.Select(label="GPIO", options=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27]), Property.Number(label="Frequency", configurable=True)]) @parameters([Property.Select(label="GPIO", options=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27]), Property.Number(label="Frequency", configurable=True)])