[SOLVED] Domoticz find just one of two flow sensors!



  • Hi to all and first sorry for my bad English!

    I link a node with some ds18b20, some relays and two flow sensors (G3/4 ; 0-60l/m) to my Domoticz with ethernet gateway. All work well without one of two flow sensors. When I look at the node setup - I see both flow sensors , but the Domoticz add just one of it to the devices. My node send the flow for both (make a pulse generator and link both to the different flow and the node send all two flows with the right value to the GW.
    In the pictures some of the DS18B20 are not connected to the node (node send only 2 for now, but all work with the temp sensors when they are connected to it)
    Will be happy to get any ideas about the problem.

    Solved - the problem was on the Domoticz. It add the flow sensor just with Node ID, in The next Beta it is fixed and adding the flow sensors with node ID and Sensor ID.

    /*
    T[0] - Refigerant Gas Temp.
    T[1] - Refrigerant Liquide Temp.
    T[2] - Heat Exchanger water input
    T[3] - Heat Exchanger water output
    T[4] - UFH water input Temp.
    T[5] - UFH water output Temp.
    T[6] - Buffer tank water input Temp.
    T[7] - Buffer tank water output Temp.
    T[8] - Buffer tank water Temp.
    F1 - water flow heat exchanger
    F2 - water flow underfloor heating from Buffer tank
    Q1 - Heat exchanger energy output to water
    Q2 - Energy from water to UFH
    */
    
    // Enable debug prints to serial monitor
    #define MY_DEBUG 
    
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    
    #include <SPI.h>
    #include <MySensors.h>
    //#include <Ethernet.h>
    #include <OneWire.h>
    #include <DallasTemperature.h>
    #include <EEPROM.h>
    //#include "EEPROMAnything.h"
    #include <MsTimer2.h>
    
    
    //1wire init
    #define ONE_WIRE_BUS A1 // Pin where dallase sensor is connected
    #define MAX_ATTACHED_DS18B20 16
    // Setup a oneWire instance to communicate with any OneWire devices
    OneWire oneWire(ONE_WIRE_BUS);
    DallasTemperature sensors(&oneWire); // Pass the oneWire reference to Dallas Temperature.
    float lastTemperature[MAX_ATTACHED_DS18B20];
    int numSensors=9;
    
    
    boolean receivedConfig = false;
    boolean metric = true; 
    
    // Initialize temperature message
    MyMessage msg(0,V_TEMP);
    // Initialize relay  message
    MyMessage msg1(22, V_LIGHT);
    // Initialize flow  message
    MyMessage flowMsg(30,V_FLOW);
    //MyMessage flowMsg2(31,V_FLOW);
    
    
    float temp, lasttemp;
    
    DeviceAddress DevAddress[9] =  {{ 0x28, 0xE2, 0x20, 0x59, 0x04, 0x00, 0x00, 0x74 }, //28E2205904000074
                                    { 0x28, 0x1B, 0xF4, 0x58, 0x04, 0x00, 0x00, 0x5E }, //281BF4580400005E
                                    { 0x28, 0x4A, 0x3E, 0x59, 0x04, 0x00, 0x00, 0x57 }, //284A3E5904000057
                                    { 0x28, 0x87, 0x86, 0x58, 0x04, 0x00, 0x00, 0x7C }, //288786580400007C
                                    { 0x28, 0xA3, 0x0C, 0x59, 0x04, 0x00, 0x00, 0xEF }, //28A30C59040000EF
                                    { 0x28, 0x4B, 0x72, 0x58, 0x04, 0x00, 0x00, 0x27 }, //284B725804000027
                                    { 0x28, 0x70, 0x40, 0x59, 0x04, 0x00, 0x00, 0xBA }, //28704059040000BA
                                    { 0x28, 0x60, 0x98, 0x59, 0x04, 0x00, 0x00, 0x81 }, //2860985904000081
                                    { 0x28, 0x9C, 0xF4, 0x58, 0x04, 0x00, 0x00, 0x31 }}; //289CF45804000031
    
    //relay init
    #define CHILD_ID_RELAY 22
    #define RELAY_1  22  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
    #define NUMBER_OF_RELAYS 5 // Total number of attached relays
    #define RELAY_ON 0  // GPIO value to write to turn on attached relay
    #define RELAY_OFF 1 // GPIO value to write to turn off attached relay
    
    
    
    //flow init
    int READ_INTERVAL = 15;           // Read interval to count the pulses (in seconds). 
    int READ_INTERVAL_MILLIS=READ_INTERVAL * 1000;        // Just to simple the math!
    long lastReadStart;
    float flow1,flow2;
    volatile unsigned long pulseCount1 = 0;
    volatile unsigned long pulseCount2 = 0;
    
    
    const byte pgenPin = 6;  // PGEN pin number
    double pgenFrequency = 55;   // pulse generator frequency (Hz)
    long pgenInterval = 1000000 / (pgenFrequency * 2);
    byte pgenState = LOW;
    long pgenPreviousMicros = 0;
    
    const byte pgenPin1 = 7;  // PGEN pin number
    double pgenFrequency1 = 110;   // pulse generator frequency (Hz)
    long pgenInterval1 = 1000000 / (pgenFrequency1 * 2);
    byte pgenState1 = LOW;
    long pgenPreviousMicros1 = 0;
    
    
    
    
    
    
    void before() { 
      for (int sensor=CHILD_ID_RELAY, pin=RELAY_1; sensor<CHILD_ID_RELAY+NUMBER_OF_RELAYS;sensor++, pin++) {
        // Then set relay pins in output mode
        pinMode(pin, OUTPUT);   
        // Set relay to last known state (using eeprom storage) 
        digitalWrite(pin, loadState(sensor)?RELAY_ON:RELAY_OFF);
      }
    }
    
    
    long loopTime,sensor_read_time;
    
    
    
    void sensorsRead() {
      sensors.requestTemperatures(); // Send the command to get temperatures
      delay(1000);
    
    // Read temperatures and send them to controller 
      for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {
     
        // Fetch and round temperature to one decimal
        float temperature = static_cast<float>(static_cast<int>((getConfig().isMetric?sensors.getTempC(DevAddress[i]):sensors.getTempFByIndex(i)) * 10.)) / 10.;
     
        // Only send data if temperature has changed and no error
        #if COMPARE_TEMP == 1
        if (lastTemperature[i] != temperature && temperature != -127.00 && temperature != 85.00) {
        #else
        if (temperature != -127.00 && temperature != 85.00) {
        #endif
     
          // Send in the new temperature
          send(msg.setSensor(i).set(temperature,1));
          // Save new temperatures for next compare
          lastTemperature[i]=temperature;
        }
      }
    } 
    
    
    
    
    
    
    void setup() {
     
       // Startup up the OneWire library
      sensors.begin();
      // requestTemperatures() will not block current thread
      sensors.setWaitForConversion(false);
    
      
      sendSketchInfo("Upravlenie HVAC", "1.1");
    
      // Present all DS18b20 sensors to controller
      for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {   
         present(i, S_TEMP);}
    
      // Present all relays to controller
      for (int sensor=CHILD_ID_RELAY, pin=RELAY_1; sensor<CHILD_ID_RELAY+NUMBER_OF_RELAYS;sensor++, pin++) {
        // Register all sensors to gw (they will be created as child devices)
        present(sensor, S_LIGHT);}
    
    
       // Present all flow meters to controller
      present(30, S_WATER); 
      present(31, S_WATER);  
       
       sensor_read_time=millis();
       lastReadStart = millis();
       pulseCount1 = 0;
       pulseCount2 = 0;
    
       attachInterrupt(digitalPinToInterrupt(2), onPulse1, RISING);  // Set flow pulse time on rising pin2
       attachInterrupt(digitalPinToInterrupt(3), onPulse2, RISING);  // Set flow pulse time on rising pin3
    
       pinMode(pgenPin, OUTPUT);
       pinMode(pgenPin1, OUTPUT);
       pinMode(2, INPUT_PULLUP);
       pinMode(3, INPUT_PULLUP);
     
    }
    
    
    
    void loop() 
    {
      pgen();
      pgen1();
      loopTime=millis();
    
    
    
    if (loopTime - lastReadStart > READ_INTERVAL_MILLIS)
      {
        flow1 = ((1.0/READ_INTERVAL)*pulseCount1)/5.5;  //Need to change here for the G type
        flow2 = ((1.0/READ_INTERVAL)*pulseCount2)/5.5;  //Need to change here for the G type
         
          send(flowMsg.setSensor(30).set(flow1,1));  //send(msg.setSensor(i).set(temperature,1));
          //delay(3000);
          send(flowMsg.setSensor(31).set(flow2,1));
          
        lastReadStart=millis();
        pulseCount1 = 0;
        pulseCount2 = 0;
      }
    
    
    if ((loopTime-sensor_read_time)>60000) {
      sensorsRead();
      sensor_read_time=millis();}
    
    }
    
    
    void receive(const MyMessage &message) {
      // We only expect one type of message from controller. But we better check anyway.
      if (message.type==V_LIGHT) {
         // Change relay state
         digitalWrite(message.sensor, message.getBool()?RELAY_ON:RELAY_OFF);
         // Store state in eeprom
         saveState(message.sensor, message.getBool());
         // Write some debug info
         Serial.print("Incoming change for sensor:");
         Serial.print(message.sensor);
         Serial.print(", New status: ");
         Serial.println(message.getBool());
       }
    }
    
    
    void onPulse1()
    {
      pulseCount1++; 
    }
    
    void onPulse2()
    {
      pulseCount2++; 
    }
    

    0_1470726372841_1.png
    0_1470726384920_2.png
    0_1470726425210_3.png


  • Contest Winner

    @vicho I really don't like these kind of construction - I know they're in the examples - but it's just not fun to read.

    I'd try this:

      // Present all DS18b20 sensors to controller
      for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {   
         present(i, S_TEMP);
         wait( 50 ); // <--- byTheo
    }
    
      // Present all relays to controller
      for (int sensor=CHILD_ID_RELAY, pin=RELAY_1; sensor<CHILD_ID_RELAY+NUMBER_OF_RELAYS;sensor++, pin++) {
        // Register all sensors to gw (they will be created as child devices)
        present(sensor, S_LIGHT);
         wait( 50 ); // <--- byTheo
    
    }
    

    When having a lot of children, I've experienced that the presentation sometimes are to fast. By adding a wait controller an node have more time.



  • 10x, I try this, but no success. The node present all children to the GW (I see it in the domoticz setup of the GW and in the MYSController), but no second device for flow in the Domoticz. Maybe will try to install Domoticz again.
    0_1470771223650_1.jpg


  • Mod

    @vicho very strange problem.

    A somewhat crazy suggestion: try changing the child id (to 39 or whatever is unused) and see if Domoticz picks up the "new" child.



  • @mfalkvidd yes, it is very strange. Before to write here I try to change the child id - first the sensors have id 50 and 51. After I try with 30, 31 and 31,32 but the same result - domoticz see just one of the flow meters. I try to reprogram GW and new node (clear both EEPROM) - note get new ID and the rusult are the same. Clear Domoticz database - same. Very strange for me. All other work well - have attached RFXTRX433 with energy monitor and some switches at 433Mhz, some nodes with light sensors and ds18b20 for testing.


Log in to reply
 

Suggested Topics

  • 3
  • 4
  • 10
  • 3
  • 2
  • 15

0
Online

11.2k
Users

11.1k
Topics

112.5k
Posts