Setting the PWM value with an external app

Can I set the PWM of a spark service from an external app? I’ve accessed the API via the swagger docs on my rig and I can see how to do many, dangerous things, but setting something in the spark service for the PWM value doesn’t appear to be one of them.

I have used brewblox to help with bread rising, controlling the fermentation temperature for making a sugar wash and also for controlling my pot still for distilling. All have worked very well indeed. My latest challenge is to see if I can use it to feed excess solar electricity into my hot water cylinder gently, rather than selling it back to the grid for a nominal amount.

I have a proof of concept working whereby I can grab how much, if any, excess power I have at any one time from the inverter. At the moment I display this figure graphically and manually set the PWM to be a calculated percentage. The result just heats the cylinder element appropriately using 0 up to 100% of the power. (The element is a low-ish power 2Kw one). As the amount of power spare varies a lot, I know I need to do this automatically.

Is setting the PWM programmatically possible? If so, I can improve my solar energy home usage quite a bit using the rig I already have when it’s not being used for bread, fermenting and distilling :slight_smile:

Yes. The same restrictions apply as when doing it in the UI: if a PID is driving the PWM, it will override your settings, and constraints on the PWM or the Digital Actuator may block or restrict your desired setting.

You can set the desired setting for your PWM in a HTTP request:

curl \
  -X POST \
  -H 'Content-Type: application/json' \
  http://localhost/spark-one/blocks/patch \
  -d '{
         "serviceId": "spark-one",
         "id": "PWM block ID",
         "type": "ActuatorPwm",
         "data": { "desiredSetting": 42, "enabled": true }

Replace localhost, spark-one, PWM block ID, and 42 with relevant values.
PWM values go from 0-100.

In a blocks/patch request you only have to include the fields you want to change.
Set the JSON data field to { "enabled": false } if you want to disable heating completely.

Relevant docs:

Edit: remembered that type is a required field. Updated example code.

Neat - thanks very much Bob; I shall give that a go

All working :slight_smile: I needed to use -X POST rather than -x POST. My server uses https on port 4430, so I needed to use a --insecure with curl in case anyone else has a similar setup.

It works very well and is fast too. I’ll be hooking this up to my Home Assistant rig in due course.

1 Like