Power sensors stopped working



  • Hi,

    I have 3 power sensors running (total, house heater and water heater). They have been working for a long time.
    Last weekend I had a power outage and they stopped working.
    Other sensors works.

    Watching in MYSController and power sensors reports V_VAR1 but message is empty.

    Any idea why?


  • Mod

    Did you try to reflash them? Did you try to do a debug to see if they are actually measuring something?



  • @jocke4u could you share some more information on your power sensors? Pictures and sketch? I am trying to replace my ubiquiti mfi setup and power sensors are my last sensors to go. Thanks!


  • Mod

    @chorob I got a sonoff pow and some gewiss material to make a similar unifi mfi, but I only have one relay



  • I have been debugging a bit now and the sensor receives pulses but the issue seems to be that it doesn't receive the old pulse count from GW (Ethernet) and therefore doesn't send the values.

    I have upgraded the GW to 2.1.1 and with the sketch below

    /**
     * The MySensors Arduino library handles the wireless radio link and protocol
     * between your home built sensors/actuators and HA controller of choice.
     * The sensors forms a self healing radio network with optional repeaters. Each
     * repeater and gateway builds a routing tables in EEPROM which keeps track of the
     * network topology allowing messages to be routed to nodes.
     *
     * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
     * Copyright (C) 2013-2015 Sensnology AB
     * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
     *
     * Documentation: http://www.mysensors.org
     * Support Forum: http://forum.mysensors.org
     *
     * This program is free software; you can redistribute it and/or
     * modify it under the terms of the GNU General Public License
     * version 2 as published by the Free Software Foundation.
     *
     *******************************
     *
     * REVISION HISTORY
     * Version 1.0 - Henrik EKblad
     * Contribution by a-lurker and Anticimex,
     * Contribution by Norbert Truchsess <norbert.truchsess@t-online.de>
     * Contribution by Tomas Hozza <thozza@gmail.com>
     *
     *
     * DESCRIPTION
     * The EthernetGateway sends data received from sensors to the ethernet link.
     * The gateway also accepts input on ethernet interface, which is then sent out to the radio network.
     *
     * The GW code is designed for Arduino 328p / 16MHz.  ATmega168 does not have enough memory to run this program.
     *
     * LED purposes:
     * - To use the feature, uncomment MY_DEFAULT_xxx_LED_PIN in the sketch below
     * - RX (green) - blink fast on radio message recieved. In inclusion mode will blink fast only on presentation recieved
     * - TX (yellow) - blink fast on radio message transmitted. In inclusion mode will blink slowly
     * - ERR (red) - fast blink on error during transmission error or recieve crc error
     *
     * See http://www.mysensors.org/build/ethernet_gateway for wiring instructions.
     *
     */
    
    // Enable debug prints to serial monitor
    #define MY_DEBUG
    
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    
    // Enable gateway ethernet module type
    #define MY_GATEWAY_W5100
    
    // W5100 Ethernet module SPI enable (optional if using a shield/module that manages SPI_EN signal)
    //#define MY_W5100_SPI_EN 4
    
    // Enable Soft SPI for NRF radio (note different radio wiring is required)
    // The W5100 ethernet module seems to have a hard time co-operate with
    // radio on the same spi bus.
    #if !defined(MY_W5100_SPI_EN) && !defined(ARDUINO_ARCH_SAMD)
    #define MY_SOFTSPI
    #define MY_SOFT_SPI_SCK_PIN 14
    #define MY_SOFT_SPI_MISO_PIN 16
    #define MY_SOFT_SPI_MOSI_PIN 15
    #endif
    
    // When W5100 is connected we have to move CE/CSN pins for NRF radio
    #ifndef MY_RF24_CE_PIN
    #define MY_RF24_CE_PIN 5
    #endif
    #ifndef MY_RF24_CS_PIN
    #define MY_RF24_CS_PIN 6
    #endif
    
    // Enable to UDP
    //#define MY_USE_UDP
    
    #define MY_IP_ADDRESS 192,168,1,11   // If this is disabled, DHCP is used to retrieve address
    // Renewal period if using DHCP
    //#define MY_IP_RENEWAL_INTERVAL 60000
    // The port to keep open on node server mode / or port to contact in client mode
    #define MY_PORT 5003
    
    // Controller ip address. Enables client mode (default is "server" mode).
    // Also enable this if MY_USE_UDP is used and you want sensor data sent somewhere.
    //#define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 254
    
    // The MAC address can be anything you want but should be unique on your network.
    // Newer boards have a MAC address printed on the underside of the PCB, which you can (optionally) use.
    // Note that most of the Ardunio examples use  "DEAD BEEF FEED" for the MAC address.
    #define MY_MAC_ADDRESS 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
    
    // Enable inclusion mode
    #define MY_INCLUSION_MODE_FEATURE
    // Enable Inclusion mode button on gateway
    //#define MY_INCLUSION_BUTTON_FEATURE
    // Set inclusion mode duration (in seconds)
    #define MY_INCLUSION_MODE_DURATION 60
    // Digital pin used for inclusion mode button
    //#define MY_INCLUSION_MODE_BUTTON_PIN  3
    
    // Set blinking period
    #define MY_DEFAULT_LED_BLINK_PERIOD 300
    
    // Flash leds on rx/tx/err
    // Uncomment to override default HW configurations
    #define MY_DEFAULT_ERR_LED_PIN 7  // Error led pin
    #define MY_DEFAULT_RX_LED_PIN  8  // Receive led pin
    #define MY_DEFAULT_TX_LED_PIN  9  // Transmit led pin
    
    
    #if defined(MY_USE_UDP)
    #include <EthernetUdp.h>
    #endif
    #include <Ethernet.h>
    #include <MySensors.h>
    
    
    void setup()
    {
    }
    
    void loop()
    {
    }
    

    Do I need to have any other implementation to save pulses?

    The Sketch for the energy meter looks like below (currently some extra printout's):

    /**
     * The MySensors Arduino library handles the wireless radio link and protocol
     * between your home built sensors/actuators and HA controller of choice.
     * The sensors forms a self healing radio network with optional repeaters. Each
     * repeater and gateway builds a routing tables in EEPROM which keeps track of the
     * network topology allowing messages to be routed to nodes.
     *
     * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
     * Copyright (C) 2013-2015 Sensnology AB
     * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
     *
     * Documentation: http://www.mysensors.org
     * Support Forum: http://forum.mysensors.org
     *
     * This program is free software; you can redistribute it and/or
     * modify it under the terms of the GNU General Public License
     * version 2 as published by the Free Software Foundation.
     *
     *******************************
     *
     * REVISION HISTORY
     * Version 1.0 - Henrik EKblad
     *
     * DESCRIPTION
     * This sketch provides an example how to implement a distance sensor using HC-SR04
     * Use this sensor to measure KWH and Watt of your house meeter
     * You need to set the correct pulsefactor of your meeter (blinks per KWH).
     * The sensor starts by fetching current KWH value from gateway.
     * Reports both KWH and Watt back to gateway.
     *
     * Unfortunately millis() won't increment when the Arduino is in
     * sleepmode. So we cannot make this sensor sleep if we also want
     * to calculate/report watt-number.
     * http://www.mysensors.org/build/pulse_power
     */
    
    // Enable debug prints
    #define MY_DEBUG
    
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    
    #define MY_NODE_ID 5
    #include <MySensors.h>
    
    #define DIGITAL_INPUT_SENSOR 3  // 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 MAX_WATT 10000          // Max watt value to report. This filetrs outliers.
    
    #define CHILD_ID 0              // Id of the sensor child
    
    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,V_WATT);
    MyMessage kwhMsg(CHILD_ID,V_KWH);
    MyMessage pcMsg(CHILD_ID,V_VAR1);
    
    
    void setup()
    {
     
      // Fetch last known pulse count value from gw
      request(CHILD_ID, V_VAR1);
    
      // 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("Heater Energy", "2.0");
    
      // Register this device as power sensor
      present(CHILD_ID, S_POWER);
    }
    
    void loop()
    {
      unsigned long now = millis();
      // Only send values at a maximum frequency or woken up from sleep
      bool sendTime = now - lastSend > SEND_FREQUENCY;
      if (pcReceived && sendTime) {
        // New watt value has been calculated
        if (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
        Serial.println("No count received. Try requesting it again");
        request(CHILD_ID, V_VAR1);
        lastSend=now;
      }
    
    }
    
    void receive(const MyMessage &message)
    {
      Serial.print("MessageType:");
      Serial.println(message.type);
      Serial.print("Message:");
      Serial.println(message.getLong());
      if (message.type==V_VAR1) {
        pulseCount = oldPulseCount = message.getLong();
        Serial.print("Received last pulse count from gw:");
        Serial.println(pulseCount);
        pcReceived = true;
      }
    }
    
    void onPulse()
    {
      Serial.println("Got Pulse");
      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++;
    }
    

    The debug log looks like:

    0 MCO:BGN:INIT NODE,CP=RNNNA--,VER=2.1.1
    3 TSM:INIT
    4 TSF:WUR:MS=0
    11 TSM:INIT:TSP OK
    13 TSM:INIT:STATID=5
    14 TSF:SID:OK,ID=5
    16 TSM:FPAR
    52 TSF:MSG:SEND,5-5-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    2060 !TSM:FPAR:NO REPLY
    2062 TSM:FPAR
    2098 TSF:MSG:SEND,5-5-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    2983 TSF:MSG:READ,0-0-5,s=255,c=3,t=8,pt=1,l=1,sg=0:0
    2989 TSF:MSG:FPAR OK,ID=0,D=1
    4106 TSM:FPAR:OK
    4107 TSM:ID
    4108 TSM:ID:OK
    4110 TSM:UPL
    4147 !TSF:MSG:SEND,5-5-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=NACK:1
    6154 TSM:UPL
    6159 TSF:MSG:SEND,5-5-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=1,st=OK:1
    6168 TSF:MSG:READ,0-0-5,s=255,c=3,t=25,pt=1,l=1,sg=0:1
    6173 TSF:MSG:PONG RECV,HP=1
    6175 TSM:UPL:OK
    6177 TSM:READY:ID=5,PAR=0,DIS=1
    6182 TSF:MSG:SEND,5-5-0-0,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0100
    6189 TSF:MSG:READ,0-0-5,s=255,c=3,t=15,pt=6,l=2,sg=0:0100
    6232 !TSF:MSG:SEND,5-5-0-0,s=255,c=0,t=17,pt=0,l=5,sg=0,ft=0,st=NACK:2.1.1
    6243 TSF:MSG:SEND,5-5-0-0,s=255,c=3,t=6,pt=1,l=1,sg=0,ft=1,st=OK:0
    6259 TSF:MSG:READ,0-0-5,s=255,c=3,t=6,pt=0,l=1,sg=0:M
    6305 !TSF:MSG:SEND,5-5-0-0,s=255,c=3,t=11,pt=0,l=13,sg=0,ft=0,st=NACK:Heater Energy
    6349 !TSF:MSG:SEND,5-5-0-0,s=255,c=3,t=12,pt=0,l=3,sg=0,ft=1,st=NACK:2.0
    6391 !TSF:MSG:SEND,5-5-0-0,s=0,c=0,t=13,pt=0,l=0,sg=0,ft=2,st=NACK:
    6397 MCO:REG:REQ
    6435 !TSF:MSG:SEND,5-5-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=3,st=NACK:2
    8476 !TSF:MSG:SEND,5-5-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=4,st=NACK:2
    10486 TSF:MSG:SEND,5-5-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=5,st=OK:2
    10493 TSF:MSG:READ,0-0-5,s=255,c=3,t=27,pt=1,l=1,sg=0:1
    10499 MCO:PIM:NODE REG=1
    10501 MCO:BGN:STP
    10528 TSF:MSG:SEND,5-5-0-0,s=0,c=2,t=24,pt=0,l=0,sg=0,ft=0,st=OK:
    Got Pulse
    10534 MCO:BGN:INIT OK,TSP=1
    Got Pulse
    Got Pulse
    Got Pulse
    Got Pulse
    Got Pulse
    Got Pulse
    No count received. Try requesting it again
    30570 !TSF:MSG:SEND,5-5-0-0,s=0,c=2,t=24,pt=0,l=0,sg=0,ft=0,st=NACK:
    Got Pulse
    Got Pulse
    Got Pulse
    Got Pulse
    Got Pulse
    Got Pulse
    Got Pulse
    No count received. Try requesting it again
    50546 TSF:MSG:SEND,5-5-0-0,s=0,c=2,t=24,pt=0,l=0,sg=0,ft=1,st=OK:
    Got Pulse
    

  • Mod

    Then it could be the controller not responding to requests for value?



  • I guess so - using openHAB 2.2.0 stable and quite late snapshot mysensors-binding for 2.2.0.
    Maybe @TimO have an idea?


  • Mod

    I remember another post about Openhab not responding to requests not long ago, maybe it is related


  • Hardware Contributor

    @gohan - I have had this issue in Domoticz as well several times. A nod requestiong a V_Var1 can sometimes takes up to 30 min to get a response and I think its something to do with timing and/or repeaters in the response. It seems like Domoticz is answering. That was the main reason i build my logger to debug this but so far I have not encountered it again.


  • Mod

    @sundberg84 said in Power sensors stopped working:

    30 min

    That is quite a lot of time


  • Hardware Contributor

    @gohan in my mind and without any evidence its like the request comes fine to the gw, responded by domoticz but the answer from the gw and back to the node gets lost through the repeater... I dont know this for sure though!


  • Mod

    without repeater it works better then?


  • Hardware Contributor

    Without any evidence - yes. I have not made that much tests yet since I waited for my logger. I have made some posts about this on the forum. I dont want to make any conclusions yet. @gohan


Log in to reply
 

Suggested Topics

71
Online

11.4k
Users

11.1k
Topics

112.7k
Posts