{"action":"created","issue":{"url":"https://api.github.com/repos/arendst/Sonoff-Tasmota/issues/1896","repository_url":"https://api.github.com/repos/arendst/Sonoff-Tasmota","labels_url":"https://api.github.com/repos/arendst/Sonoff-Tasmota/issues/1896/labels{/name}","comments_url":"https://api.github.com/repos/arendst/Sonoff-Tasmota/issues/1896/comments","events_url":"https://api.github.com/repos/arendst/Sonoff-Tasmota/issues/1896/events","html_url":"https://github.com/arendst/Sonoff-Tasmota/issues/1896","id":296747198,"number":1896,"title":"Water Meter Config Sonoff basic","user":{"login":"miley786","id":36446295,"avatar_url":"https://avatars3.githubusercontent.com/u/36446295?v=4","gravatar_id":"","url":"https://api.github.com/users/miley786","html_url":"https://github.com/miley786","followers_url":"https://api.github.com/users/miley786/followers","following_url":"https://api.github.com/users/miley786/following{/other_user}","gists_url":"https://api.github.com/users/miley786/gists{/gist_id}","starred_url":"https://api.github.com/users/miley786/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/miley786/subscriptions","organizations_url":"https://api.github.com/users/miley786/orgs","repos_url":"https://api.github.com/users/miley786/repos","events_url":"https://api.github.com/users/miley786/events{/privacy}","received_events_url":"https://api.github.com/users/miley786/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2018-02-13T14:01:31Z","updated_at":"2018-05-07T13:27:10Z","closed_at":null,"author_association":"NONE","body":"Hi \r\n\r\nWe have been using the the sonoff basic for a few configurations with it and the Tasmota firmware, at this point we are trying to implement a water meter sensor on the sonoff using one of the GPIO's to act as the input for the readings.\r\n\r\nWe have a project running with the water meter working on a Arduino UNO running the code below:\r\n\r\nbyte` statusLed    = 13;\r\nbyte sensorInterrupt = 0;\r\nbyte sensorPin       = 2;\r\n\r\nfloat calibrationFactor = 4.5; // Change depending on sensor\r\nvolatile byte pulseCount;\r\nfloat flowRate;\r\nunsigned int flowMilliLitres;\r\nunsigned long totalMilliLitres;\r\nunsigned long oldTime;\r\n\r\nvoid setup()\r\n{\r\n  Serial.begin(9600);  // Initialize a serial connection for reporting values to the host\r\n  pinMode(statusLed, OUTPUT);  // Set up the status LED line as an output\r\n  digitalWrite(statusLed, HIGH);  // We have an active-low LED attached\r\n\r\n  pinMode(sensorPin, INPUT);\r\n  digitalWrite(sensorPin, HIGH);\r\n\r\n  pulseCount        = 0;\r\n  flowRate          = 0.0;\r\n  flowMilliLitres   = 0;\r\n  totalMilliLitres  = 0;\r\n  oldTime           = 0;\r\n\r\n  // The Hall-effect sensor is connected to pin 2 which uses interrupt 0.\r\n  // Configured to trigger on a FALLING state change (transition from HIGH\r\n  // state to LOW state)\r\n  attachInterrupt(sensorInterrupt, pulseCounter, FALLING);\r\n}\r\n\r\nvoid loop()\r\n{\r\n  if ((millis() - oldTime) > 1000)   // Only process counters once per second\r\n  {\r\n    // Disable the interrupt while calculating flow rate and sending the value to\r\n    // the host\r\n    detachInterrupt(sensorInterrupt);\r\n\r\n    // Because this loop may not complete in exactly 1 second intervals we calculate\r\n    // the number of milliseconds that have passed since the last execution and use\r\n    // that to scale the output. We also apply the calibrationFactor to scale the output\r\n    // based on the number of pulses per second per units of measure (litres/minute in\r\n    // this case) coming from the sensor.\r\n    flowRate = ((1000.0 / (millis() - oldTime)) * pulseCount) / calibrationFactor;\r\n\r\n    // Note the time this processing pass was executed. Note that because we've\r\n    // disabled interrupts the millis() function won't actually be incrementing right\r\n    // at this point, but it will still return the value it was set to just before\r\n    // interrupts went away.\r\n    oldTime = millis();\r\n\r\n    // Divide the flow rate in litres/minute by 60 to determine how many litres have\r\n    // passed through the sensor in this 1 second interval, then multiply by 1000 to\r\n    // convert to millilitres.\r\n    flowMilliLitres = (flowRate / 60) * 1000;\r\n\r\n    // Add the millilitres passed in this second to the cumulative total\r\n    totalMilliLitres += flowMilliLitres;\r\n\r\n    unsigned int frac;\r\n\r\n    // Print the flow rate for this second in litres / minute\r\n    Serial.print(\"Flow rate: \");\r\n    Serial.print(int(flowRate));  // Print the integer part of the variable\r\n    Serial.print(\"L/min\");\r\n    Serial.print(\"\\t\"); \t\t  // Print tab space\r\n\r\n    // Print the cumulative total of litres flowed since starting\r\n    Serial.print(\"Output Liquid Quantity: \");\r\n    Serial.print(totalMilliLitres);\r\n    Serial.println(\"mL\");\r\n    Serial.print(\"\\t\"); \t\t  // Print tab space\r\n    Serial.print(totalMilliLitres / 1000);\r\n    Serial.print(\"L\");\r\n\r\n\r\n    // Reset the pulse counter so we can start incrementing again\r\n    pulseCount = 0;\r\n\r\n    // Enable the interrupt again now that we've finished sending output\r\n    attachInterrupt(sensorInterrupt, pulseCounter, FALLING);\r\n  }\r\n}\r\n\r\nvoid pulseCounter()\r\n{\r\n  // Increment the pulse counter\r\n  pulseCount++;\r\n}\r\n\r\nIs it possible to modify this code and include this in the tasmota firmware? and list it as a water sensor? since the MQTT configurations are already running on it? it would allow for a simple integration for a water meter to an automation system\r\n\r\nPlease let me know if its possible.\r\n\r\nThanking in advance"},"comment":{"url":"https://api.github.com/repos/arendst/Sonoff-Tasmota/issues/comments/387064248","html_url":"https://github.com/arendst/Sonoff-Tasmota/issues/1896#issuecomment-387064248","issue_url":"https://api.github.com/repos/arendst/Sonoff-Tasmota/issues/1896","id":387064248,"user":{"login":"EricVdB","id":17044143,"avatar_url":"https://avatars0.githubusercontent.com/u/17044143?v=4","gravatar_id":"","url":"https://api.github.com/users/EricVdB","html_url":"https://github.com/EricVdB","followers_url":"https://api.github.com/users/EricVdB/followers","following_url":"https://api.github.com/users/EricVdB/following{/other_user}","gists_url":"https://api.github.com/users/EricVdB/gists{/gist_id}","starred_url":"https://api.github.com/users/EricVdB/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/EricVdB/subscriptions","organizations_url":"https://api.github.com/users/EricVdB/orgs","repos_url":"https://api.github.com/users/EricVdB/repos","events_url":"https://api.github.com/users/EricVdB/events{/privacy}","received_events_url":"https://api.github.com/users/EricVdB/received_events","type":"User","site_admin":false},"created_at":"2018-05-07T13:27:10Z","updated_at":"2018-05-07T13:27:10Z","author_association":"NONE","body":"I'm interested in this as well. I have this setup for both my water and gas meter using 2 hall effect sensors.\r\nThey are both connected to an ESP32 which also has the PZEM004 for power consumption.\r\nI would like to move completely to Tasmota and get rid of all the other stuff.\r\nPlan is to have an ESP8266 for each (electricity, water and gas).\r\n\r\nBesides that, I use Tasmota to measure the temps of my pool solar panels and the pool, and control the pump with another Tasmota through OpenHab. Reporting is done with Grafana.\r\n\r\nI hope we see soon a decent counter implementation that reports counter, L/min, today consumption, yesterdays consumption, total consumption like is reported by the PZEM004 module.\r\n\r\nThanks in advance,\r\nEric "}}
{"actor":{"display_login":"EricVdB"}}