ArduCounter: Unterschied zwischen den Versionen

Aus FHEMWiki
Zur Navigation springen Zur Suche springen
K (Bilder ergänzt)
 
Zeile 291: Zeile 291:


;interval <normal> <max> [<min> <min count> [<analog interval> <analog samples>]]  
;interval <normal> <max> [<min> <min count> [<analog interval> <analog samples>]]  
:Defines the parameters that affect the way counting and reporting works.
:Defines the parameters that affect the way counting and reporting works. This Attribute expects at least two and a maximum of six numbers as value. The first is the normal interval, the second the maximal interval, the third is a minimal interval and the fourth is a minimal pulse count. The last two numbers are only needed for counting with reflective light barriers. They specify the delay between the measurements and the number of samples for each measurement. The normal use case (where the normal interval is smaller than the maximum interval) would be where the Arduino board just counts and remembers the time between the first impulse and the last impulse for each pin.After the normal interval has elapsed the Arduino board reports the count and time for those pins where impulses were encountered.This means that even though the normal interval might be 10 seconds, the reported time difference can be different because impulses are observed by start and end point. The Power (e.g. for energy meters) is then calculated based of the counted impulses and the time difference between the first and the last impulse.For the next interval, the starting time will be the time of the last impulse in the previous reporting period and the time difference will be taken up to the last impulse before the reporting interval has elapsed. The second, third and fourth numbers (maximum, minimal interval and minimal count) exist for edge cases where the pulse frequency is very low and the reporting time is comparatively short: For example if the normal interval (first number) is 60 seconds but there is only one impulse every 90 seconds you will have spikes in your power readings (where there should be none).This can be avoided by choosing the max/min/min count numbers wisely: If impulses occur less frequently than the normal interval readings will be prolonged until max interval is reached. If however the last max interval has had no pulses, a new max interval has just started and right after it started an impuls occurs this would again cause spikes the way Arducounter works. To prevent those spikes from happening use <min> / <min count>. They make sure, that more than <min count> impulses and less than <min> time between impulses must have occured for the impulses to be considered as part of a normal interval (=a steady flow of impulses). If however it's just a single impulse which comes at an "akward" moment as mentioned before it won't be considered during a normal interval unless other impulses follow. Instead the normal interval will be prolonged until max interval is reached.
:This Attribute expects at least two and a maximum of six numbers as value.  
:A reasonable example would be:<syntaxhighlight lang="perl" xstyle="width:80%;">
:The first is the normal interval, the second the maximal interval, the third is a minimal interval and the fourth is a minimal pulse count.  
:The last two numbers are only needed for counting with reflective light barriers. They specify the delay between the measurements  
:and the number of samples for each measurement.
:
:In the usual operation mode (when the normal interval is smaller than the maximum interval),
:the Arduino board just counts and remembers the time between the first impulse and the last impulse for each pin.
:After the normal interval is elapsed the Arduino board reports the count and time for those pins where impulses were encountered.
:This means that even though the normal interval might be 10 seconds, the reported time difference can be  
:something different because it observed impulses as starting and ending point.
:The Power (e.g. for energy meters) is then calculated based of the counted impulses and the time between the first and the last impulse.  
:For the next interval, the starting time will be the time of the last impulse in the previous reporting period  
:and the time difference will be taken up to the last impulse before the reporting interval has elapsed.
:
:The second, third and fourth numbers (maximum, minimal interval and minimal count) exist for the special case
:when the pulse frequency is very low and the reporting time is comparatively short.
:For example if the normal interval (first number) is 60 seconds and the device counts only one impulse in 90 seconds,
:the the calculated power reading will jump up and down and will give ugly numbers.
:By adjusting the other numbers of this attribute this can be avoided.
:In case in the normal interval the observed impulses are encountered in a time difference that is smaller than the third number (minimal interval)
:or if the number of impulses counted is smaller than the fourth number (minimal count) then the reporting is delayed until the maximum interval has elapsed
:or the above conditions have changed after another normal interval.
:This way the counter will report a higher number of pulses counted and a larger time difference back to fhem.  
:Example:
:<syntaxhighlight lang="perl" xstyle="width:80%;">
attr myCounter interval 60 600 5 2
attr myCounter interval 60 600 5 2
</syntaxhighlight>  
</syntaxhighlight>If this is seems too complicated and you prefer a simple and constant reporting interval, then you can set the normal interval and the mximum interval to the same number.This changes the operation mode of the counter to just count during this normal and maximum interval and report the count. In this case the reported time difference is always the reporting interval and not the measured time between the real impulses.
:If this is seems too complicated and you prefer a simple and constant reporting interval, then you can set the normal interval and the mximum interval to the same number.  
:This changes the operation mode of the counter to just count during this normal and maximum interval and report the count.  
:In this case the reported time difference is always the reporting interval and not the measured time between the real impulses.
:
:For analog sampling the last two numbers define the delay in milliseconds between analog measurements and the number of samples that will be taken as one mesurement.
:For analog sampling the last two numbers define the delay in milliseconds between analog measurements and the number of samples that will be taken as one mesurement.


Zeile 532: Zeile 504:
;devVerbose  
;devVerbose  
:this attribute is outdated and has been replaced with the attributes  
:this attribute is outdated and has been replaced with the attributes  
:<syntaxhighlight lang="perl" xstyle="width:80%;">enableHistory, enableSerialEcho, enablePinDebug, enableAnalogDebug, enableDevTime<syntaxhighlight lang="perl" xstyle="width:80%;">
:<nowiki><syntaxhighlight lang="perl" xstyle="width:80%;">enableHistory, enableSerialEcho, enablePinDebug, enableAnalogDebug, enableDevTime<syntaxhighlight lang="perl" xstyle="width:80%;"></nowiki>




Zeile 585: Zeile 557:
:If a water meter which outputs 10 impulses per liter on its digital output is for example connected to GPIO pin D6,  
:If a water meter which outputs 10 impulses per liter on its digital output is for example connected to GPIO pin D6,  
:then if the attribute runTimeD6 is set to 1, the reading runTimeD6 will show for how many seconds the water has been flowing without a stop longer than the  
:then if the attribute runTimeD6 is set to 1, the reading runTimeD6 will show for how many seconds the water has been flowing without a stop longer than the  
:observation interval specifie in the interval-attribute. This is helpful when you want to create alerts in case someone forgot to close a water tap.
:observation interval specifie in the interval-attribute. This is helpful when you want to create alerts in case someone forgot to close a water tap. [[Kategorie:Other Components]] [[Kategorie:Energieverbrauchsmessung]]
 
[[Kategorie:Other Components]]
[[Kategorie:Energieverbrauchsmessung]]

Aktuelle Version vom 29. September 2021, 20:44 Uhr

ArduCounter
Zweck / Funktion
Count pulses, measure time between pulses and convert this to readings for e.g. power consumption of Energy meters or water meters
Allgemein
Typ Gerätemodul
Details
Dokumentation EN / DE
Thema
Support (Forum) Sonstiges
Modulname 98_ArduCounter.pm
Ersteller StefanStrobel (Forum / Wiki)
Wichtig: sofern vorhanden, gilt im Zweifel immer die (englische) Beschreibung in der commandref!


This module implements an Interface to an Arduino, ESP8266 or ESP32 based counter for pulses on any input pin of an Arduino Uno, Nano, Jeenode, NodeMCU, Wemos D1, TTGO T-Display or similar device.

Wasserzähler mit Laserabtastung auf Basis ArduCounter mit ESP32
ArduCounter auf einem ESP32
ArduCounter mit Reflexlichtschranke auf einem ESP8266
ArduCounter mit Reflexlichtschranke auf einem ESP8266
ArduCounter Wifi-Konfiguration per WifiManager

The device connects to Fhem either through USB / serial or via Wifi / TCP if an ESP board is used. ArduCounter does not only count pulses but also measure pulse lenghts and the time between pulses so it can filter noise / bounces and gives better power/flow (Watts or liters/second) readings than systems that just count in fixed time intervals. The number of pulses per kWh or liter is defineable and counters continue even when Fhem or the device restarts so you don't need additional user readings to make such calculations The typical use case is an S0-Interface on an energy meter or water meter, but also reflection light barriers to monitor old ferraris counters or analog water meters are supported Counters are configured with attributes that define which GPIO pins should count pulses and in which intervals the board should report the current counts. The sketch that works with this module uses pin change interrupts so it can efficiently count pulses on all available input pins. The module has been tested with 14 inputs of an Arduino Uno counting in parallel and pulses as short as 3 milliseconds. The module creates readings for pulse counts, consumption and optionally also a pin history with pulse lengths and gaps of the last pulses. If an ESP8266 or ESP32 is used, the device can be flashed and configured over Wifi (it opens its own temporary Hotspot / SSID for configuration so you can set which existing SSID to connect to and which password to use). For TTGO T-Display boards (ESP32 with TFT display) the local display on the device itself can also display Wifi status and current consumption.

Prerequisites

This module requires an Arduino Uno, Nano, Jeenode, NodeMCU, Wemos D1, TTGO T-Display or similar device based on an Atmel 328p, ESP8266 or ESP32 running the ArduCounter sketch provided with this module In order to flash an arduino board with the corresponding ArduCounter firmware from within Fhem, avrdude needs to be installed. To flash ESP32 or ESP8266 boards form within Fhem, Python and the scripts esptool.py / espota.py need to be installed. For old ferraris counters a reflection light barrier which in the simpest case can consist of a photo transistor (connected to an anlalog input of the Arduino / ESP) and an led or a laser module (connected to a digital output), both with a resistor in line are needed. To drive a laser module with 5V, another transistor is typically needed to switch 5V from a 3.3V GPIO output.

Define

define <name> ArduCounter <device> or define <name> ArduCounter <ip:port>

<device> specifies the serial port to communicate with the Arduino. <ip:port> specifies the ip address and tcp port to communicate with an esp8266 / ESP32 where port is typically 80.

The name of the serial device depends on your distribution and serial adapter. You can also specify a baudrate for serial connections if the device name contains the @ character, e.g.: /dev/ttyUSB0@115200 The default baudrate of the ArduCounter firmware is 115200 since sketch version 4 and used to be 38400 since sketch version 1.4 The latest version of this module will however try different baudrates automatically if communication with the counting device seems not possible.

Example:

define AC ArduCounter /dev/ttyUSB2@115200 define AC ArduCounter 192.168.1.134:80

Configuration of ArduCounter digital counters

Specify the pins where impulses should be counted e.g. as attr AC pinX falling pullup min 25 The X in pinX can be an Arduino / ESP GPIO pin number with or without the letter D e.g. pin4, pinD5, pin6, pinD7 ... After the pin you can use the keywords falling or rising to define if a logical one / 5V (rising) or a logical zero / 0V (falling) should be treated as pulse. The optional keyword pullup activates the pullup resistor for the given Pin. The last argument is also optional but recommended and specifies a minimal pulse length in milliseconds. An energy meter with S0 interface is typically connected to GND and an input pin like D4. The S0 pulse then pulls the input down to 0V. Since the minimal pulse lenght of an S0 interface is specified to be 30ms, the typical configuration for an s0 interface is attr AC pinX falling pullup min 25 Specifying a minimal pulse length is recommended since it filters bouncing of reed contacts or other noise. The keyword min before 25 is optional.

Example:

define AC ArduCounter /dev/ttyUSB2
attr AC pulsesPerUnit 1000
attr AC interval 60 300
attr AC pinD4 falling pullup min 5
attr AC pinD5 falling pullup min 25
attr AC pinD6 rising

This defines a counter that is connected to Fhem via serial line ttyUSB2 with three counters connected to the GPIO pins D4, D5 and D5. D4 and D5 have their pullup resistors activated and the impulses draw the pins to zero. For D4 and D5 the board measures the time in milliseconds between the falling edge and the rising edge. If this time is longer than the specified 5 (or 25 for pin D5) milliseconds then the impulse is counted. If the time is shorter then this impulse is regarded as noise and added to a separate reject counter. For pin D6 the board uses a default minimal length of 2ms and counts every time when the signal changes from 1 (rising pulse) back to 0.

Configuration of ArduCounter analog counters

This module and the corresponding ArduCounter sketch can be used to read water meters or old analog ferraris energy counters. Therefore a reflection light barrier needs to be connected to the board. This might simply consist of an infra red photo transistor (connected to an analog input) and an infra red led (connected to a digital output), both with a resistor in line. The idea comes from Martin Kompf (https://www.kompf.de/tech/emeir.html) and has been adopted for ArduCounter to support old ferraris energy counters or water meters. The configuration is then similar to the one for digital counters:

define WaterMeter ArduCounter 192.168.1.110:80
attr ACF pinA0 rising pullup min 4 analog out 27 threshold 120,220
attr ACF interval 5,60,2,15,10,3
attr ACF pulsesPerUnit 35
attr ACF stateFormat {sprintf("%.3f l/min", ReadingsVal($name,"powerA0",0))}

In this case an analog GPIO pin is used as input and the normal configuration parameters are followed by the keyword analog out or simply out, the gpio number of a GPIO output that connects a light source and the thresholds that decide when an analog input value is regarded as "low" or "high".

In the example an ESP32 is used via Wifi connection. GPIO pin A0 is used as analog input and is connected to a photo transistor that senses the intensity of light. GPIO 27 is used as LED output and switched on/off in a high frequency. On GPIO A0 the reflected light is measured and the difference in a measurement between when the LED is off and when the LED is on is compared to the thresholds defined in the pinA0-attribute. When the measured light difference is above 220, then a pulse starts (since rising is specified). When the measured difference is below 120 then the pulse ends.

The attribute interval has the following meaning in the above example: The device reports the current counts and the time difference beween the first and the last pulse if at least 2 pulses have been counted and if they are more than 15 milliseconds apart form each other. If not, then the device continues counting. If after 60 seconds these conditions are stil not met, then the device will report the current count anyways and use the current time as the end of the interval. The last two numbers of the interval attribute define that the device will read the analog input 3 times and then work with the average. Between each analog measurement series there will be a delay of 10 milliseconds.

The attribute pulsesPerUnit 35 defines that 35 pulses correspond to one unit (e.g. liter) and the reading calcCounterA0 is increased by the reported raw counts divided by 35. To find out the right analog thresholds you can set the attribute enableHistory to 1 which will ask the firmware of your counting board to report the average difference measurements before they are compared to a threshold. The ArduCounter module will count how often each value is reported and you can then query these analog level counts with get levels. After a few measuremets the result of get levels might look like this:

observed levels from analog input:
94: 21
95: 79
96: 6
97: 2
98: 3
99: 2
100: 2
101: 1
102: 3
105: 2
106: 1
108: 2
109: 1
110: 1
112: 1
113: 3
115: 4
116: 9
117: 14
118: 71
119: 103
120: 118
121: 155
122: 159
123: 143
124: 147
125: 158
126: 198
127: 249
128: 220
129: 230
130: 201
131: 140
132: 147
133: 153
134: 141
135: 119
136: 105
137: 109
138: 114
139: 83
140: 33
141: 14
142: 1  

This shows the measured values together with the frequency how often the individual value has been measured. It is obvious that most measurements result in values between 120 and 135, very few values are betweem 96 and 115 and another peak is around the value 95. It means that in the example of a ferraris energy counter, when the red mark of the ferraris disc is under the sensor, the value is around 95 and while when the blank disc is under the sensor, the value is typically between 120 and 135. So a good upper threshold would be 120 and a good lower threshold would be for example 96.

Set-Commands

raw
send the value to the board so you can directly talk to the sketch using its commands.
This is not needed for normal operation but might be useful sometimes for debugging
flash [<file>]
flashes the ArduCounter firmware from the subdirectory FHEM/firmware onto the device.
Normally you can just specify set myDevice flash. The parameter <file> is optional and allows specifying an alternative firmware file.
The attribute flashCommand can be used to override which command is executed.
If the attribute flashCommand is not specified then the module selects an appropriate command depending on the board type
(set with the attribute board) and depending on the connection (serial or Wifi).
For an arduino NANO for example the module would execute avrdude (which has to be installed of course)
and flash the connected arduino with the updated hex file
(by default it looks for ArduCounter.hex in the FHEM/firmware subdirectory).
For an Arduino UNO for example the default is avrdude -p atmega328P -c arduino -P [PORT] -D -U flash:w:[HEXFILE] 2>[LOGFILE]
For an Arduino Nano based counter -b 57600 is added.
For an ESP32 connected via Wifi, the module would call espota.py which will upload the firmware over the air.
If the attribute flashCommand is not specified for an ESP32 based board connected via serial line, then the module uses the command
esptool.py --chip esp32 --port [PORT] --baud 460800 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 40m --flash_size detect
0x1000 FHEM/firmware/ArduCounter_ESP32_bootloader_dio_40m.bin 0x8000 FHEM/firmware/ArduCounter_ESP32_partitions.bin 0xe000  FHEM/firmware/ArduCounter_ESP32_boot_app0.bin
0x10000 FHEM/firmware/ArduCounter_ESP32_firmware.bin >[LOGFILE] 2>&1
for example which flashes the whole ESP32 with all the partitions. For over the air flashing it would use
espota.py -i[IP] -p [NETPORT] -f [BINFILE] 2>[LOGFILE]
Of course esptool.py or espota.py as well as python would need to be installed on the system.
resetWifi
reset Wifi settings of the counting device so the Wifi Manager will come up after the next reset to select a wireless network and enter the Wifi passphrase.
reset
sends a command to the device which causes a hardware reset or reinitialize and reset of the internal counters of the board.
The module then reopens the counting device and resends the attribute configuration / definition of the pins.
saveConfig
stores the current interval, analog threshold and pin configuration in the EEPROM of the counter device so it will automatically be retrieved after a reset.
enable
sets the attribute disable to 0
disable

sets the attribute disable to 1

reconnect
closes the tcp connection to an ESP based counter board that is conected via TCP/IP and reopen the connection
clearLevels
clears the statistics for analog levels. This is only relevant if you use the board to read via a reflective light barrier
and you want to set the thresholds according to the statistics.
clearCounters <pin>
resets all the counter readings for the specified pin to 0
counter <pin>, <value>
set the calcCounter reading for the specified pin to the given value
clearHistory
deletes all the cached pin history entries

Get-Commands

info
send a command to the Arduino board to get current counts.
This is not needed for normal operation but might be useful sometimes for debugging
levels
show the count for the measured levels if an analog pin is used to measure e.g. the red mark of a ferraris counter disc. This is useful for setting the thresholds for analog :measurements.
history <pin>
shows details regarding all the level changes that the counter device (Arduino or ESP) has detected and how they were used (counted or rejected)
If get history is issued with a pin name (e.g. get history D5) then only the history entries concerning D5 will be shown.
This information is sent from the device to Fhem if the attribute enableHistory is set to 1.
The maximum number of lines that the Arducounter module stores in a ring buffer is defined by the attribute maxHist and defaults to 1000.


Attributes

do_not_notify
readingFnAttributes
pin[AD]?[0-9]+<rising|falling> [<pullup>] [min] <min length> [[analog] out <out pin> [threshold] <min, max>]
Define a GPIO pin of the Arduino or ESP board as input. This attribute expects for digital inputs either
rising or falling, followed by an optional pullup and the optional keyword min
and an optional number as minimal length of pulses and gaps between pulses.
The counter device will track rising and falling edges of each impulse and measure the length of a pulse in milliseconds.
The minimal length specified here is the minimal duration of a pulse and a pause before a pulse. If one is too small,
the pulse is not counted but added to a separate reject counter.
Example:
attr MyCounter pinD4 falling pullup 25
For analog inputs with connected reflective light barries, you have to add analog out
and the GPIO pin number of the pin where the light source (LED or laser) is connected, the keyword threshold
followed by the lower and upper threshold separated by a komma.
Example:
attr MyCounter pinA0 rising pullup min 3 analog out 27 threshold 120,220
interval <normal> <max> [<min> <min count> [<analog interval> <analog samples>]]
Defines the parameters that affect the way counting and reporting works. This Attribute expects at least two and a maximum of six numbers as value. The first is the normal interval, the second the maximal interval, the third is a minimal interval and the fourth is a minimal pulse count. The last two numbers are only needed for counting with reflective light barriers. They specify the delay between the measurements and the number of samples for each measurement. The normal use case (where the normal interval is smaller than the maximum interval) would be where the Arduino board just counts and remembers the time between the first impulse and the last impulse for each pin.After the normal interval has elapsed the Arduino board reports the count and time for those pins where impulses were encountered.This means that even though the normal interval might be 10 seconds, the reported time difference can be different because impulses are observed by start and end point. The Power (e.g. for energy meters) is then calculated based of the counted impulses and the time difference between the first and the last impulse.For the next interval, the starting time will be the time of the last impulse in the previous reporting period and the time difference will be taken up to the last impulse before the reporting interval has elapsed. The second, third and fourth numbers (maximum, minimal interval and minimal count) exist for edge cases where the pulse frequency is very low and the reporting time is comparatively short: For example if the normal interval (first number) is 60 seconds but there is only one impulse every 90 seconds you will have spikes in your power readings (where there should be none).This can be avoided by choosing the max/min/min count numbers wisely: If impulses occur less frequently than the normal interval readings will be prolonged until max interval is reached. If however the last max interval has had no pulses, a new max interval has just started and right after it started an impuls occurs this would again cause spikes the way Arducounter works. To prevent those spikes from happening use <min> / <min count>. They make sure, that more than <min count> impulses and less than <min> time between impulses must have occured for the impulses to be considered as part of a normal interval (=a steady flow of impulses). If however it's just a single impulse which comes at an "akward" moment as mentioned before it won't be considered during a normal interval unless other impulses follow. Instead the normal interval will be prolonged until max interval is reached.
A reasonable example would be:
attr myCounter interval 60 600 5 2
If this is seems too complicated and you prefer a simple and constant reporting interval, then you can set the normal interval and the mximum interval to the same number.This changes the operation mode of the counter to just count during this normal and maximum interval and report the count. In this case the reported time difference is always the reporting interval and not the measured time between the real impulses.
For analog sampling the last two numbers define the delay in milliseconds between analog measurements and the number of samples that will be taken as one mesurement.
pulsesPerUnit <number>
specify the number of pulses that the meter is giving out per unit that sould be displayed (e.g. per kWh energy consumed).
For many S0 counters this is 1000, for old ferraris counters this is 75 (rounds per kWh).
This attribute used to be called pulsesPerKWh and this name still works but the new name should be used preferably since the old one could be removed in future versions.
Example:
attr myCounter pulsesPerUnit 75
readingPulsesPerUnit[AD]?[0-9]+ <number>
is the same as pulsesPerUnit but specified per GPIO pin individually in case you have multiple counters with different settings at the same time
This attribute used to be called readingPulsesPerKWh[AD]?[0-9]+ and this name still works but the new name should be used preferably
since the old one could be removed in future versions.
Example:
attr myCounter readingPulsesPerUnitA7 75
attr myCounter readingPulsesPerUnitD4 1000
readingFlowUnitTime[AD]?[0-9]+
specified the time period in seconds which is used as the basis for calculating the current flow or power for the given pin.
If the counter e.g. counts liters and you want to see the flow in liters per minute, then you have to set this attribute to 60.
If you count kWh and you want to see the current power in kW, then specify 3600 (one hour).
Since this attribute is just used for multiplying the consumption per second, you can also use it to get watts
instead of kW by using 3600000 instead of 3600.
flowUnitTime
like readingFlowUnitTimeXX but applies to all pins that have no explicit readingFlowUnitTimeXX attribute.
readingNameCount[AD]?[0-9]+ <new name>
Change the name of the counter reading pinX to something more meaningful.
Example:
attr myCounter readingNameCountD4 CounterHaus_internal
readingNameLongCount[AD]?[0-9]+ <new name>
Change the name of the long counter reading longX to something more meaningful.
Example:
attr myCounter readingNameLongCountD4 CounterHaus_long
readingNameInterpolatedCount[AD]?[0-9]+ <new name>
Change the name of the interpolated long counter reading InterpolatedlongX to something more meaningful.
Example:
attr myCounter readingNameInterpolatedCountD4 CounterHaus_interpolated
readingNameCalcCount[AD]?[0-9]+ <new name>
Change the name of the real unit counter reading CalcCounterX to something more meaningful.
Example:
attr myCounter readingNameCalcCountD4 CounterHaus_kWh
readingNamePower[AD]?[0-9]+ <new name>
Change the name of the power reading powerX to something more meaningful.
Example:
attr myCounter readingNamePowerD4 PowerHaus_kW
readingStartTime[AD]?[0-9]+ [0|1]
Allow the reading time stamp to be set to the beginning of measuring intervals.
This is a hack where the timestamp of readings is artificially set to a past time and may have side effects
so avoid it unless you fully understand how Fhem works with readings and their time.
verboseReadings[AD]?[0-9]+ [0|1]
create the additional readings lastMsg and pinHistory for each pin
if verboseReafings is set to 1 for the specified pin.
If set to -1 then the internal counter, the long counter and interpolated long counter readings will be hidden.
Example:
attr myCounter verboseReadingsD4 1
enableHistory [0|1]
tells the counting device to record the individual time of each change at each GPIO pin and send it to Fhem.
This information is cached on the Fhem side and can be viewed with the command get history
The optput of get history will look like this:
seq  12627 2020-03-22 20:39:54 Pin D5   0.080 seconds at 0 -> pulse counted
seq  12628 2020-03-22 20:39:55 Pin D5   1.697 seconds at 1 -> gap
seq  12629 2020-03-22 20:39:56 Pin D5   0.080 seconds at 0 -> pulse counted
seq  12630 2020-03-22 20:39:56 Pin D5   1.694 seconds at 1 -> gap
seq  12631 2020-03-22 20:39:58 Pin D5   0.081 seconds at 0 -> pulse counted
seq  12632 2020-03-22 20:39:58 Pin D5   1.693 seconds at 1 -> gap
seq  12633 2020-03-22 20:40:00 Pin D5   0.081 seconds at 0 -> pulse counted
seq  12634 2020-03-22 20:40:00 Pin D5   1.696 seconds at 1 -> gap
seq  12635 2020-03-22 20:40:02 Pin D5   0.081 seconds at 0 -> pulse counted
seq  12636 2020-03-22 20:40:02 Pin D5   1.699 seconds at 1 -> gap
seq  12637 2020-03-22 20:40:03 Pin D5   0.079 seconds at 0 -> pulse counted
seq  12638 2020-03-22 20:40:03 Pin D5   1.700 seconds at 1 -> gap
seq  12639 2020-03-22 20:40:05 Pin D5   0.080 seconds at 0 -> pulse counted
seq  12642 2020-03-22 20:40:05 Pin D5   1.699 seconds at 1 -> gap
seq  12643 2020-03-22 20:40:07 Pin D5   0.080 seconds at 0 -> pulse counted
seq  12644 2020-03-22 20:40:07 Pin D5   1.698 seconds at 1 -> gap
enableSerialEcho [0|1]
tells the counting device to show diagnostic data over the serial line when connected via TCP
enablePinDebug [0|1]
tells the counting device to show every level change of the defined input pins over the serial line or via TCP
enableAnalogDebug [0|1]
tells the counting device to show every analog measurement of the defined analog input pins over the serial line or via TCP
enableDevTime [0|1]
tells the counting device to show its internal millis timer so a drift between the devices time and fhem time can be calculated and logged
maxHist <max entries>
specifies how many pin history lines hould be buffered for "get history".
This attribute defaults to 1000.
analogThresholds
this Attribute is outdated. Please specify the analog thresholds for reflective light barrier input with the attribute "pin..."
flashCommand <new shell command>
overrides the default command to flash the firmware via Wifi (OTA) or serial line. It is recommended to not define this attribute.
Example:
attr myCounter flashCommand avrdude -p atmega328P -c arduino -b 57600 -P [PORT] -D -U flash:w:[HEXFILE] 2>[LOGFILE]
[PORT] is automatically replaced with the serial port for this device as it is specified in the define command.
[HEXFILE] or [BINFILE] are synonyms and are both automatically replaced with the firmware file appropriate for the device.
For ESP32 boards [HEXFILE] would be replaced by ArduCounter-8266.bin for example.
[LOGFILE] is automatically replaced ArduCounterFlash.log in the fhem log subdirectory.
[NETPORT] is automatically replaced by the tcp port number used for OTA flashing.
For ESP32 this usually is 3232 and for 8266 Bords it is 8266.
keepAliveDelay <delay>
defines an interval in which the module sends keepalive messages to a counter device that is conected via tcp.
This attribute is ignored if the device is connected via serial port.
If the device doesn't reply within a defined timeout then the module closes and tries to reopen the connection.
The module tells the device when to expect the next keepalive message and the device will also close the tcp connection if it doesn't see a keepalive message within the delay :multiplied by 3
The delay defaults to 10 seconds.
Example:
attr myCounter keepAliveDelay 30
keepAliveTimeout <seconds>
defines the timeout when wainting for a keealive reply (see keepAliveDelay)
The timeout defaults to 2 seconds.
Example:
attr myCounter keepAliveTimeout 3
keepAliveRetries <max number of retries>
defines how often sending a keepalive is retried before the connection is closed and reopened.
It defaults to 2.
Example:
attr myCounter keepAliveRetries 3
nextOpenDelay <delay>
defines the time in seconds that the module waits before retrying to open a disconnected tcp connection.
This defaults to 60 seconds.
Example:
attr myCounter nextOpenDelay 20
openTimeout <timeout>
defines the timeout in seconds after which tcp open gives up trying to establish a connection to the counter device.
This timeout defaults to 3 seconds.
Example:
attr myCounter openTimeout 5
silentReconnect [0|1]
if set to 1, then it will set the loglevel for "disconnected" and "reappeared" messages to 4 instead of 3
Example:
attr myCounter silentReconnect 1
deviceDisplay <pin> <unit> <flowUnit>
controls the unit strings that a local display on the counting device will show.
Example:
attr myCounter deviceDisplay 36,l,l/m
attr myCounter deviceDisplay 36,kWh,kW
disable [0|1]
if set to 1 then the module is disabled and closes the connection to a counter device.
factor
Define a multiplicator for calculating the power from the impulse count and the time between the first and the last impulse.
This attribute is outdated and unintuitive so you should avoid it.
Instead you should specify the attribute pulsesPerUnit or readingPulsesPerUnit[0-9]+ (where [0-9]+ stands for the pin number).
readingFactor[AD]?[0-9]+
Override the factor attribute for this individual pin.
Just like the attribute factor, this is a rather cumbersome way to specify the pulses per kWh.
Instead it is advised to use the attribute pulsesPerUnit or readingPulsesPerUnit[0-9]+ (where [0-9]+ stands for the pin number).
devVerbose
this attribute is outdated and has been replaced with the attributes
<syntaxhighlight lang="perl" xstyle="width:80%;">enableHistory, enableSerialEcho, enablePinDebug, enableAnalogDebug, enableDevTime<syntaxhighlight lang="perl" xstyle="width:80%;">


Readings / Events

The module creates at least the following readings and events for each defined pin:

calcCounter.*
This is recommended reading for counting units based on the pulses and the attribute pulsesPerUnit. It is similar to interpolated long count
which keeps on counting up after fhem restarts but this counter will take the pulses per Unit attribute into the calculation und thus does not
count pulses but real Units (kWh, liters or some other unit that is applicable)
The name of this reading can be changed with the attribute readingNameCalcCount[AD]?[0-9]+ where [AD]?[0-9]+ stands for the pin description e.g. D4.
Another reading with the same name but ending in _i (e.g. calcCounterD4_i) will show how many kWh (or other units) of the above value is interpolated.
pin.* e.g. pinD4
the current internal count at this pin (internal to the Arduino / ESP device, starts at 0 when the device restarts).
The name of this reading can be changed with the attribute readingNameCount[AD]?[0-9]+ where [AD]?[0-9]+ stands for the pin description e.g. D4
long.* e.g. longD5
long count which keeps on counting up after fhem restarts whereas the pin.* count is only a temporary internal count that starts at 0 when the arduino board starts.
The name of this reading can be changed with the attribute readingNameLongCount[AD]?[0-9]+ where [AD]?[0-9]+ stands for the pin description e.g. D4
interpolatedLong.*
like long.* but when the Arduino restarts the potentially missed pulses are interpolated based on the pulse rate before the restart and after the restart.
The name of this reading can be changed with the attribute readingNameInterpolatedCount[AD]?[0-9]+ where [AD]?[0-9]+ stands for the pin description e.g. D4
reject.*
counts rejected pulses that are shorter than the specified minimal pulse length.
power.*
the current calculated power / flow at this pin.
The name of this reading can be changed with the attribute readingNamePower[AD]?[0-9]+ where [AD]?[0-9]+ stands for the pin description e.g. D4.
This reading depends on the attributes pulsesPerUnit as well as readingFlowUnitTime or flowUnitTime for calculation
pinHistory.*
shows detailed information of the last pulses. This is only available when a minimal pulse length is specified for this pin. Also the total number of impulses recorded here is :limited to 20 for all pins together. The output looks like -36/7:0C, -29/7:1G, -22/8:0C, -14/7:1G, -7/7:0C, 0/7:1G
The first number is the relative time in milliseconds when the input level changed, followed by the length in milliseconds, the level and the internal action.
-36/7:0C for example means that 36 milliseconds before the reporting started, the input changed to 0V, stayed there for 7 milliseconds and this was counted.
countDiff.*
delta of the current count to the last reported one. This is used together with timeDiff.* to calculate the power consumption.
timeDiff.*
time difference between the first pulse in the current observation interval and the last one. Used togehter with countDiff to calculate the power consumption.
seq.*
internal sequence number of the last report from the board to Fhem.
runTime.*
this reading will only be created when the attribute runTime[AD]?[0-9]+ is set for a given pin.
It contains the time in seconds that the consumption / flow observed at the specified pin has not ben zero.
If a water meter which outputs 10 impulses per liter on its digital output is for example connected to GPIO pin D6,
then if the attribute runTimeD6 is set to 1, the reading runTimeD6 will show for how many seconds the water has been flowing without a stop longer than the
observation interval specifie in the interval-attribute. This is helpful when you want to create alerts in case someone forgot to close a water tap.