Cloud variable vs pub/sub

Just curious what the advantage is between the two? Could someone (someone who feels they have time) just outline when one would use cloud variable and when one would use pub/sub?

I have a use case and I’m wondering if it might be suited to cloud variable more than pub/sub but I’m not sure why…

I’d like to have a physical toggle switch which I could toggle when I want all my devices to stop issuing audible notifications. I THINK it would be more sensible for this toggle to update a cloud variable than it would to send a publish but being a bit new to all this I can’t really articulate WHY I think cloud variable seems to make more sense to me. And maybe it shouldn’t!

Particle.variables() can be altered in your code numerous times without ever causing any network traffic, only when someone requests the current value, the value is transmitted to the cloud. So this is always an action that’s initiated from the cloud side and never from the device side. The value is only stored in the device and never in the cloud.
Particle.publish() pushes an event into the cloud, so that’s always initiated by the device and not by the cloud.
Particle.subscribe() “reacts” to an event from the cloud - which could have been pushed from the same device or another or even from any other source that can publish Particle events.

4 Likes