Send value from Domoticz to MySensor node



  • Hello,

    I've tried to use the Power Meter Pulse example of MySensors website, but I can't initialize the first kwh value with the current meter index.
    Thus, I would like to send the index manually via Domoticz to initialize a variable in the Arduino sketch of the node.

    Do you know how I can set a value in Domoticz and send it to a MySensors node to store it in a variable please ?

    Thanks in advance for your help.

    Baptiste


  • Hardware Contributor

    @moumout31 - there are some discussions about this on the forum. Here is one for example: https://forum.mysensors.org/topic/2101/pulse-water-meter



  • @sundberg84 Thanks for your help.
    It seems to answer my problem, I will try what is done on this topic.



  • I tried to debug my sketch but when I request the last know value from gateway request(CHILD_ID_PMPINIT, V_KWH);, I have no answer from the gateway.

    Contrary to the MySensors example Power Meter Pulse, after several tries, I've created a new Child in order to store the init value of meter and to be able to update it via json.

    You can see the sketch here below.

    Thanks for your help.

    Baptiste

    #include "_04_Headers.h"
    #include "Arduino.h"
    #include <SPI.h>
    #include <SoftwareSerial.h>
    
    //**********Init MySensors**********
    // Enable debug prints to serial monitor
    #define MY_DEBUG
    
    // Enable and select radio type attached
    #define MY_RADIO_RFM69
    
    #define MY_RFM69_FREQUENCY RF69_433MHZ
    
    #define MY_RF69_IRQ_PIN 3
    #define MY_RF69_IRQ_NUM 1
    
    // Define a lower baud rate for Arduino's running on 8 MHz (Arduino Pro Mini 3.3V & SenseBender)
    #if F_CPU == 8000000L
    #define MY_BAUD_RATE 38400
    #endif
    
    #include <MySensors.h>
    
    //**********Init téléinfo**********
    unsigned long loopCounter = 0L;
    unsigned long BASET=0;
    unsigned long BASETt=0; //BASET temporaire
    unsigned long PAPPT=0;
    unsigned long IINSTT=0;
    unsigned long Pcalc=0;
    unsigned long Conso=0;
    
    int j=1;
    int z=1;
    
    TeleInfo* myTeleInfo;
    
    #define CHILD_ID_COMPTEURPV 0
    #define CHILD_ID_COMPTEURPVVA 2
    #define CHILD_ID_COMPTEURPVI 3
    
    MyMessage kWhPVmsg(CHILD_ID_COMPTEURPV, V_KWH);
    MyMessage WPVmsg(CHILD_ID_COMPTEURPV, V_WATT);
    MyMessage VAPVmsg(CHILD_ID_COMPTEURPVVA, V_VA);
    MyMessage IPVmsg(CHILD_ID_COMPTEURPVI, V_CURRENT);
    
    unsigned long SENDstartTeleInfo=0;
    
    //**********Init température**********
    #include <OneWire.h>
    
    #define CHILD_ID_TEMP 1
    
    MyMessage TEMPmsg(CHILD_ID_TEMP, V_TEMP);
    
    unsigned long SENDstartTemp=0;
    
    const int DS18S20_Pin = 5; //DS18S20 Signal pin on digital 5
    const int DS18B20_ID = 0x28;
    OneWire ds(DS18S20_Pin);  // on digital pin 5
    
    //***********Init POWER METER PULSE**********
    #define DIGITAL_INPUT_SENSOR 2  // The digital input you attached your light sensor.  (Only 2 and 3 generates interrupt!)
    #define PULSE_FACTOR 1000       // Nummber of blinks per KWH of your meeter
    #define SLEEP_MODE false        // Watt-value can only be reported when sleep mode is false.
    #define MAX_WATT 10000          // Max watt value to report. This filetrs outliers.
    #define CHILD_ID_PMP 4             // Id of the sensor child
    #define CHILD_ID_PMPINIT 5
    
    unsigned long SEND_FREQUENCY = 20000; // Minimum time between send (in milliseconds). We don't wnat to spam the gateway.
    double ppwh = ((double)PULSE_FACTOR)/1000; // Pulses per watt hour
    bool pcReceived = false;
    volatile unsigned long pulseCount = 0;
    volatile unsigned long lastBlink = 0;
    volatile unsigned long watt = 0;
    unsigned long oldPulseCount = 0;
    unsigned long oldWatt = 0;
    double oldKwh;
    unsigned long lastSend;
    
    MyMessage wattMsg(CHILD_ID_PMP,V_WATT);
    MyMessage kwhMsg(CHILD_ID_PMP,V_KWH);
    MyMessage pcMsg(CHILD_ID_PMPINIT,V_KWH);
    
    void onPulse() {
        if (!SLEEP_MODE) {
            unsigned long newBlink = micros();
            unsigned long interval = newBlink-lastBlink;
            if (interval<10000L) { // Sometimes we get interrupt on RISING
                return;
            }
            watt = (3600000000.0 /interval) / ppwh;
            lastBlink = newBlink;
        }
        pulseCount++;
    }
    
    float getTemp() {
    }
    
    void setup() 
    {
      //Serial.begin(57600);
      //Serial.println(F("\nStarting ..."));
      delay(300);
      // starting TeleInfo capture
      myTeleInfo = new TeleInfo(version);
    
      // Fetch last known pulse count value from gw
      request(CHILD_ID_PMPINIT, V_KWH);
    
      // Use the internal pullup to be able to hook up this sketch directly to an energy meter with S0 output
      // If no pullup is used, the reported usage will be too high because of the floating pin
      pinMode(DIGITAL_INPUT_SENSOR,INPUT_PULLUP);
      attachInterrupt(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), onPulse, RISING);
      lastSend=millis();
    }
    
    void presentation()
    {
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo("Tableau electrique", "1.0");
    
      // Register all sensors to gateway (they will be created as child devices)
      present(CHILD_ID_COMPTEURPV, S_POWER);
      present(CHILD_ID_COMPTEURPVVA, S_POWER);
      present(CHILD_ID_COMPTEURPVI, S_MULTIMETER);
      present(CHILD_ID_TEMP, S_TEMP);
      present(CHILD_ID_PMP, S_POWER);
      present(CHILD_ID_PMPINIT, S_POWER);
    }
    
    void receive(const MyMessage &message)
    {
        if (message.type==V_KWH) {
            pulseCount = oldPulseCount = message.getLong();
            Serial.print("Received last pulse count from gw:");
            Serial.println(pulseCount);
            pcReceived = true;
        }
    }
    
    void loop() 
    {
    //**********1er cycle de calcul**********
      float temp;
      boolean teleInfoReceived;
      if (j==1) {
        temp = getTemp(); //acquisition température
        temp = getTemp();
        send(TEMPmsg.set(temp,1));
        while(z==1) //tant qu'on n'acquiert pas de téléinfo
        {
          teleInfoReceived = myTeleInfo->readTeleInfo();
          if(teleInfoReceived)
          {
            BASET=myTeleInfo->BASET;
            PAPPT=myTeleInfo->PAPPT;
            IINSTT=myTeleInfo->IINSTT;
            z=2;
          }
        }
        j=2;
      }
      
    //**********Téléinfo**********
    
      // we parse the teleInfo frame
      teleInfoReceived = myTeleInfo->readTeleInfo();
    
      if(teleInfoReceived)
      {
        BASETt=myTeleInfo->BASET;
        PAPPT=myTeleInfo->PAPPT;
        IINSTT=myTeleInfo->IINSTT;
    
        if((BASETt>BASET) && (BASETt-BASET<1000) && (BASETt<500000)) {
          BASET=BASETt;
        }
    
        //Calcul des informations
        //Puissance efficace instantannée en Watt
        Pcalc=IINSTT*(float)230;
        
        // Envoi des donnees
        if((millis() - SENDstartTeleInfo > 3000))
        {
          SENDstartTeleInfo=millis();
         
          send(kWhPVmsg.set(BASET/(float)1000,3));
          send(VAPVmsg.set(PAPPT));
          send(IPVmsg.set(IINSTT)); 
          send(WPVmsg.set(Pcalc)); 
        }
      }
    
      //**********Consommation électrique*********
      unsigned long now = millis();
      // Only send values at a maximum frequency or woken up from sleep
      bool sendTime = now - lastSend > SEND_FREQUENCY;
      if (pcReceived && (SLEEP_MODE || sendTime)) {
          // New watt value has been calculated
          if (!SLEEP_MODE && watt != oldWatt) {
              // Check that we dont get unresonable large watt value.
              // could hapen when long wraps or false interrupt triggered
              if (watt<((unsigned long)MAX_WATT)) {
                  send(wattMsg.set(watt));  // Send watt value to gw
              }
              Serial.print("Watt:");
              Serial.println(watt);
              oldWatt = watt;
          }
    
          // Pulse cout has changed
          if (pulseCount != oldPulseCount) {
              send(pcMsg.set(pulseCount));  // Send pulse count value to gw
              double kwh = ((double)pulseCount/((double)PULSE_FACTOR));
              oldPulseCount = pulseCount;
              if (kwh != oldKwh) {
                  send(kwhMsg.set(kwh, 4));  // Send kwh value to gw
                  oldKwh = kwh;
              }
          }
          lastSend = now;
      } else if (sendTime && !pcReceived) {
          // No count received. Try requesting it again
          request(CHILD_ID_PMPINIT, V_KWH);
          lastSend=now;
      }
    
      if (SLEEP_MODE) {
          sleep(SEND_FREQUENCY);
      }
      
      //**********Température**********
      float temp1 = getTemp(); //acquisition température
    
      if((millis() - SENDstartTemp > 30000) && (temp1 > (float)5))
        {
          temp=temp1;
          Serial.print("Temperature : ");
          Serial.println(temp);
          send(TEMPmsg.set(temp,1));
          SENDstartTemp=millis();
        }
    }```


  • @moumout31 Nobody knows how to help me please ?

    Thanks


  • Hero Member

    @moumout31 domoticz only responds to requests for a few types of sensors. KWh is not one of them. You can try to work with V_TEXT.



  • @AWI Thanks a lot for yout answer ! I will try this !



  • @moumout31
    I think it is not true, what AWI writes.
    I try pulse meter example now on RS485 bus, and I am receiving last value from Domoticz when restarting node .
    When I reset or power off node, it then continues sending form last value.
    This value it must obtain from domoticz.


  • Hero Member

    @kimot the pulse meter uses the V_VAR datatype. This can be written to and requested from Domoticz from the MySensors network. However there is no mechanism in Domoticz to set the value. So yes, a useful method for storing variables, but treated somewhat strange on the Domoticz side.



  • Thanks a lot, it works using V_TEXT instead of V_KWH !


Log in to reply
 

Suggested Topics

  • 5
  • 8
  • 3
  • 4
  • 4
  • 5

65
Online

11.4k
Users

11.1k
Topics

112.7k
Posts