Pulse Counter on standard Digital input pin


Hello, All!
I’m trying to turn on a relay, count a specific number of pulses on a digital input, then turn the relay off. I can’t find a way to count the pulses in Cayenne. Any ideas?



I also didn’t know how to do it with Cayenne, but you can write your code and use Cayenne only for monitoring the number of the pulses and IF you reach specify number, you can use Triggers to turn ON/OFF the relay.

What kind of platform do you use? I recommend to count the pulses in your algorithm and send them as a Number to the Cayenne.


If you want to see de pulses in Cayenne dashboard just do (If you are using arduino):

Cayenne.virtualWrite(VIRTUAL_PIN, pulses);

However, if you want to make the pulses with a button from Cayenne dashboard just drag and drop a button and:

int pulses;
if(getValue.asInt() == 1){

Or with a 1 - 2 state button

int pulses;

Did I understand you?


I’m using a Raspberry Pi Zero to as an irrigation controller. I have it working with Python code, but was wondering if I could do it with Cayenne. I use GPIO.event_detect to count the pulses of a water meter (1 gal/pulse). I wasn’t aware that I could send that data to Cayenne. I’ll look into it. Thanks for the idea!


If you have the code already in python then you are 75% of the way there. You just need to install the Cayenne MQTT library and send the data via MQTT. Here are some links that will get you where you need to be, post back if you need any help!

https://github.com/myDevicesIoT/Cayenne-MQTT-Python (or you can also use the paho MQTT library)


Thanks, Adam. I looked at the pydoc and understand all the methods except
the “topic” methods (getCommandTopic, getResponseTopic, & getDataTopic).
Where can I find more details about these?



I’m not sure what those are either. Can you post the link where you found it?


They are in the Methods section of the pydoc for Cayenne. I get to it by clicking “Python 3.5 Module Docs” under the Python group in the Windows menu (I have Python installed on my Windows 10 machine). The address in the browser that it goes to is “http://localhost:50648/cayenne.client.html”.


Does this comments from the code help you? I think these are the methods for populating, communication and updating the data to the cayenne?

def getDataTopic(self, channel):
        """Get the data topic string.
        channel is the channel to send data to.
        return "%s/%s/%s" % (self.rootTopic, DATA_TOPIC, channel)
    def getCommandTopic(self):
        """Get the command topic string."""
        return "%s/%s/+" % (self.rootTopic, COMMAND_TOPIC)

    def getResponseTopic(self):
        """Get the response topic string."""
        return "%s/%s" % (self.rootTopic, RESPONSE_TOPIC)


The comments help a bit, but I still don’t understand what the “Topics” are used for. I’d love to see a good example.


Here’s a nice MQTT tutorial: http://www.hivemq.com/blog/mqtt-essentials-part-1-introducing-mqtt