This introduces a Pulse Width Modulation module for openHAB.
PWM can be used to control actuators continuously from 0 to 100% that only support ON/OFF commands. E.g. valves or heating burners. It accomplishes that by switching the actuator on and off with a fixed interval. The higher the control percentage (duty cycle), the longer the ON phase.
The linked documentation and the screenshots in the thread were outdated. The module is part of the official release, now. You need to add an âItem Actionâ instead. I updated the screenshot and the link to the documentation in the original post.
To configure a rule, you need to add a Trigger (âPWM triggersâ) and an Action (âItem Actionâ). Select the Item you like to control in the âItem Actionâ and leave the command empty.
It worked. The problem that tricked me was this - when a corrected rule is saved, one needs to update DutyCycleItem value in order the process to restart.
Thanks for this, I can definitely see its uses! Iâm looking at this for my heating system,where if I need 20% duty on two outputs, and 30% on a 3rd, Iâd like them to all start their cycle at the same point in time, so the first 20% of the interval is shared with all 3 of them on, then two switch off, and 10% later the final one switches off, and theyâre all then off together.
If I have multiple PWM rules, with a common interval, can I get them to sync up? Or will they naturally do this?
If they are started at the same time (e.g. when OH is started), they should run synchronized and diverge very very slowly. I guess I can change the code to eliminate the slow diverging, but I first want to hear your experience.
Thank you for the prompt reply! Iâll investigate swapping over a couple of rooms to use this (plus the recently added PID control) and will let you know!
Is it possible to run over a group of PWM-sources?
Lets say Iâve got 13 floor heating items (0âŠ100%) and need to control 13 valves, do I need to setup 13 PWM triggeres (one for each item) or can I use groups ( and handle value item names within scripts).
I have everything in the same naming:
floor1_temperature
floor1_setpoint
floor1_pwm
floor1_value
floor1_temperature is firing my rules now, in the rule script iâm matching item points using:
var = event.itemName.replace(â_temperatureâ, â_setpointâ);
var = event.itemName.replace(â_temperatureâ, â_pwmâ);
var = event.itemName.replace(â_temperatureâ, â_valueâ);
Am I able to use the PWM rule to walk through the 15 group members '_pwm", and then using something like above scripting to set corresponding â_valveâ items?
Sure, you can set up one PWM module and feed all your Items with the PWM output via a rule/script. To build a regulation, you might want to use the PID Controller module. But in general, this is more a question on rules, than PWM-specific.
@fwolter one more question - how the interval should be set, my use case is :
heating valve actuator NC with 180 second needed to fully open the valve after switching it on
PID conntroller â PWM â Relay. Should this interval time by somehow synced with PID controller timings?
I am not sure if i understood the readme:)
The interval doesnât need to be synced with the PID controller, if the loop time of the PID controller is much faster than the interval of the PWM (maybe 10 times). Doesnât hurt to decrease the interval of the PID controller, anyway.
If your valves need 180s to open, Iâd start with an PWM interval of maybe factor 5, i.e. 15min in your case.
hi @fwolter, thank you! itâs working well. One interesting behaviour during some testing / jss scripting.
If i want to disable PWM rule from .js - âvacation settingâ
rules.setEnabled(`Termostat_1_PWM_rule`,false) i get:
Failed to execute rule 'Termostat_1_modes_management': Fail to execute action: 1
2022-06-08 19:38:44.367 [ERROR] [tomation.script.file.rulesCreator.js] - Failed to execute rule Termostat_7_modes_management: java.util.concurrent.RejectedExecutionException: Task java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask@65e27b99[Not completed, task = java.util.concurrent.Executors$RunnableAdapter@132d2e1d[Wrapped task = org.openhab.core.automation.internal.TriggerHandlerCallbackImpl$TriggerData@562fa21c]] rejected from java.util.concurrent.ScheduledThreadPoolExecutor@6733b492[Terminated, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 1]
2022-06-08 19:38:44.373 [ERROR] [e.automation.internal.RuleEngineImpl] - Failed to execute rule 'Termostat_7_modes_management': Fail to execute action: 1
rules |modes_management" are only a proxy for setting right work mode, but the issue is when this rules executes disabling the PWM rule. i can without errors disable other rules even the PID controller automation, but with PWM i get this
not crucial i can set deadmanswitch and disable PID controller rule only, but maybe it;s possible to fix it
p.s.
what is interesting i can disable /enable the rule when i use GUI and put only a single line in a script
rules.setEnabled(Termostat_1_PWM_rule,false) or true but log is showing:
2022-06-08 19:48:07.812 [WARN ] [.internal.OpenhabGraalJSScriptEngine] - Failed to retrieve script script dependency listener from engine bindings. Script dependency tracking will be disabled.
2022-06-08 19:48:48.565 [WARN ] [.internal.OpenhabGraalJSScriptEngine] - Failed to retrieve script script dependency listener from engine bindings. Script dependency tracking will be disabled.
2022-06-08 19:48:55.475 [WARN ] [.internal.OpenhabGraalJSScriptEngine] - Failed to retrieve script script dependency listener from engine bindings. Script dependency tracking will be disabled.
Hi,
i am using PID and PWM on few hosts. Have one problem with the PWM module, which randomly (cant find out exact behavior) stops sending ON/OFF command to an action item even if the dutycycle item is 0 or 100 . Donât know the exact reason and how to reproduce it.
when i change manually relay to ON and OFF again
2022-11-07 21:07:24.093 [INFO ] [openhab.event.ItemCommandEvent ] - Item âRadiatorAC5_PWM_dutycycleItemâ received command 100.0
2022-11-07 21:07:33.701 [INFO ] [openhab.event.ItemCommandEvent ] - Item âRadiatorAC5_PWM_Relayâ received command ON
2022-11-07 21:07:33.720 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item âRadiatorAC5_PWM_Relayâ predicted to become ON
2022-11-07 21:07:33.746 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item âRadiatorAC5_PWM_Relayâ changed from OFF to ON
2022-11-07 21:07:38.900 [INFO ] [openhab.event.ItemCommandEvent ] - Item âRadiatorAC5_PWM_Relayâ received command OFF
2022-11-07 21:07:38.909 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item âRadiatorAC5_PWM_Relayâ predicted to become OFF
2022-11-07 21:07:38.929 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item âRadiatorAC5_PWM_Relayâ changed from ON to OFF
2022-11-07 21:07:54.090 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item âRadiatorAC5_PID_iInspectorâ changed from 0.92525552 to 1.3480696133333332
2022-11-07 21:07:54.098 [INFO ] [openhab.event.ItemCommandEvent ] - Item âRadiatorAC5_PWM_dutycycleItemâ received command 100.0
but still no ON command after that
Logs:
2022-11-07 20:52:24.056 [INFO ] [openhab.event.ItemCommandEvent ] - Item 'RadiatorAC5_PWM_dutycycleItem' received command 100.0
2022-11-07 20:52:54.055 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'RadiatorAC5_PID_iInspector' changed from 83.28955768000003 to 83.85237644000003
2022-11-07 20:52:54.058 [INFO ] [openhab.event.ItemCommandEvent ] - Item 'RadiatorAC5_PWM_dutycycleItem' received command 100.0
2022-11-07 20:53:24.066 [INFO ] [openhab.event.ItemCommandEvent ] - Item 'RadiatorAC5_PWM_dutycycleItem' received command 100.0
2022-11-07 20:53:24.076 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'RadiatorAC5_PID_iInspector' changed from 83.85237644000003 to 84.41519520000003
2022-11-07 20:53:54.058 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'RadiatorAC5_PID_iInspector' changed from 84.41519520000003 to 84.97801396000003
2022-11-07 20:53:54.060 [INFO ] [openhab.event.ItemCommandEvent ] - Item 'RadiatorAC5_PWM_dutycycleItem' received command 100.0
2022-11-07 20:54:24.058 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'RadiatorAC5_PID_iInspector' changed from 84.97801396000003 to 85.54083272000003
2022-11-07 20:54:24.060 [INFO ] [openhab.event.ItemCommandEvent ] - Item 'RadiatorAC5_PWM_dutycycleItem' received command 100.0
2022-11-07 20:54:54.059 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'RadiatorAC5_PID_iInspector' changed from 85.54083272000003 to 86.10365148000002
2022-11-07 20:54:54.064 [INFO ] [openhab.event.ItemCommandEvent ] - Item 'RadiatorAC5_PWM_dutycycleItem' received command 100.0
2022-11-07 20:55:11.993 [INFO ] [openhab.event.ItemCommandEvent ] - Item 'RadiatorAC5_PID_commandItem' received command RESET
2022-11-07 20:55:11.997 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'RadiatorAC5_PID_commandItem' changed from NULL to RESET
2022-11-07 20:55:12.001 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'RadiatorAC5_PID_commandItem' changed from RESET to NULL
2022-11-07 20:55:24.065 [INFO ] [openhab.event.ItemCommandEvent ] - Item 'RadiatorAC5_PWM_dutycycleItem' received command 100.0
2022-11-07 20:55:24.071 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'RadiatorAC5_PID_iInspector' changed from 86.10365148000002 to 0.56281876
2022-11-07 20:55:54.067 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'RadiatorAC5_PID_iInspector' changed from 0.56281876 to 1.12563752
2022-11-07 20:55:54.069 [INFO ] [openhab.event.ItemCommandEvent ] - Item 'RadiatorAC5_PWM_dutycycleItem' received command 100.0
2022-11-07 20:56:24.065 [INFO ] [openhab.event.ItemCommandEvent ] - Item 'RadiatorAC5_PWM_dutycycleItem' received command 100.0
2022-11-07 20:56:24.069 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'RadiatorAC5_PID_iInspector' changed from 1.12563752 to 1.68845628
2022-11-07 20:56:54.067 [INFO ] [openhab.event.ItemCommandEvent ] - Item 'RadiatorAC5_PWM_dutycycleItem' received command 100.0
2022-11-07 20:56:54.072 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'RadiatorAC5_PID_iInspector' changed from 1.68845628 to 2.25127504
ok i got it⊠Disabling and Enabling the rule again fix the problem but donât know for how long:
2022-11-07 21:10:34.183 [INFO ] [openhab.event.ItemCommandEvent ] - Item 'RadiatorAC5_PWM_Relay' received command OFF
2022-11-07 21:10:34.196 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'RadiatorAC5_PWM_Relay' predicted to become OFF
2022-11-07 21:10:54.138 [INFO ] [openhab.event.ItemCommandEvent ] - Item 'RadiatorAC5_PWM_dutycycleItem' received command 100.0
2022-11-07 21:10:54.144 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'RadiatorAC5_PID_iInspector' changed from 3.457061346666667 to 3.874275253333334
2022-11-07 21:10:54.159 [INFO ] [openhab.event.ItemCommandEvent ] - Item 'RadiatorAC5_PWM_Relay' received command ON
2022-11-07 21:10:54.164 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'RadiatorAC5_PWM_Relay' predicted to become ON
2022-11-07 21:10:54.174 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'RadiatorAC5_PWM_Relay' changed from OFF to ON
2022-11-07 21:11:24.139 [INFO ] [openhab.event.ItemCommandEvent ] - Item 'RadiatorAC5_PWM_dutycycleItem' received command 100.0
2022-11-07 21:11:24.145 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'RadiatorAC5_PID_iInspector' changed from 3.874275253333334 to 4.291503066666667
but still it seems like an error to me. I can add that i am using some enable/disable rules which are triggered by IOS app - when i turn off thermostat i disable the PID and PWM rule, and then enabling them again if you choose different mode.
OK PID controller produces the dutycycleitem and PWM has itâs own cycle which is a bit slower. Can somebody confirm that on every PWM cycle relay items should get ON / OFF command even if the relay item already has correct ON/OFF state ?
The PWM module sends a command always, regardless of the state of the target Item.
If you still encounter problems you can enable the logging for org.openhab.automation.pwm at TRACE level. This will show the state changes of the PWM module internal state machine.