IR Node resending last signal ca every 15 minutes



  • Hi,

    I attached a TSOP 38238 to my arduino pro mini (3v) wit the goal of relaying IR signals to my controller (Home Assistant). On the face of it everything works: When I press a button on my tv remote a message is sent. But: about every 15 minutes the node resends the last IR command it has seen.

    Also attached to the node is a lux sensor and a temp/humidity sensor that are pulled every 90 seconds (I don't need updated temp/hum/lux values every time somebody presses a button on the remote).

    The IR sensor is attached to pin 3 and wakes the sensor up every time there is new data. When the ardunio is woken up it checks whether it was by interrupt or by time an then checks the corresponding sensor.

    Can anybody see what I am doing wrong here? Here is a pic of the sensor in Home Assistant:

    cf11c834-59a6-4668-9b70-f561c78a318b-image.png ![alt text](image url)

    This is from last night, all lights are off and nobody used the remote. I can't find a reason why the node wakes up ~ every 15 minutes.

    Does anybody have an idea or a workaround?

    sketch:

    
    
    // Enable debug prints
    //#define MY_DEBUG
    
    //#define MY_OWN_DEBUG
    
    #ifndef MY_OWN_DEBUG //disable serial in production compile, potentially saves few uA in sleep mode
         #define MY_DISABLED_SERIAL
    #endif
    
    
    // Enable and select radio type attached
    #define MY_RADIO_RFM69
    #define MY_IS_RFM69HW
    #define MY_RFM69_NEW_DRIVER
    
    
    #define MY_NODE_ID 3
    #include <MySensors.h>
    
    // IR specific setup  
    #include <IRremote.h>
    int RECV_PIN     = 3;
    IRrecv            irrecv(RECV_PIN);
    decode_results    ircode;
    const char * TYPE2STRING[] = {
        "UNKONWN",
        "RC5",
        "RC6",
        "NEC",
        "Sony",
        "Panasonic",
        "JVC",
        "SAMSUNG",
        "Whynter",
        "AIWA RC T501",
        "LG",
        "Sanyo",
        "Mitsubishi",
        "Dish",
        "Sharp",
        "Denon"
    };
    #define Type2String(x)   TYPE2STRING[x < 0 ? 0 : x]
    #define AddrTxt          F(" addres: 0x")
    #define ValueTxt         F(" value: 0x")
    #define NATxt            F(" - not implemented/found")
    unsigned long last_value;
    // IR specific setup end
    
    #define CHILD_ID_HUM  0
    #define CHILD_ID_TEMP 1
    #define CHILD_ID_LUX  2
    #define CHILD_ID_IR 3
    
    #define SKETCH_NAME "mysensors_wohnzimmer_main"
    #define SKETCH_MAJOR_VER "1"
    #define SKETCH_MINOR_VER "0"
    
    static bool metric = true;
    
    int BATTERY_SENSE_PIN = A0;  // select the input pin for the battery sense point
    int oldBatteryPcnt = 0;
    
    float lastHum = 0;
    float lastTemp = 0;
    int lastLux = 0;
    
    
    // Sleep time between sensor updates (in milliseconds)
    static const unsigned long UPDATE_INTERVAL = 90000;
    
    #include <SI7021.h>
    #include <BH1750.h>
    
    static SI7021 tempsensor;
    BH1750 lightmeter;
    
    
    
    MyMessage msgHum(CHILD_ID_HUM, V_HUM);
    MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
    MyMessage msgLux(CHILD_ID_LUX, V_LEVEL);
    MyMessage msgIrRecord(CHILD_ID_IR, V_IR_RECEIVE); 
    
    
    
    void presentation()  
    { 
     // Send the sketch version information to the gateway and Controller
      sendSketchInfo(SKETCH_NAME, SKETCH_MAJOR_VER "." SKETCH_MINOR_VER);
    
      present(CHILD_ID_HUM, S_HUM);
       present(CHILD_ID_TEMP, S_TEMP);
      present(CHILD_ID_LUX, S_LIGHT_LEVEL);
      present(CHILD_ID_IR, S_IR);
    }
    
    void setup()
    {
      while (not tempsensor.begin())
      {
        Serial.println(F("Temperaturesensor not detected!"));
        delay(5000);
      }
        #ifdef MY_OWN_DEBUG
        Serial.println("Tempsensor started");
      #endif
      lightmeter.begin();
      #ifdef MY_OWN_DEBUG
        Serial.print("UPDATE_INTERVAL:");Serial.println(UPDATE_INTERVAL);
      #endif
      irrecv.enableIRIn();
    }
    
    
    void loop(){
      int8_t wake_reason;
      sleep_bod_disable();//disable BOD  - saves~ 15uA
      wake_reason = sleep(RECV_PIN-2, RISING, UPDATE_INTERVAL);
      #ifdef MY_OWN_DEBUG
      Serial.print("wake_reason=");Serial.println(wake_reason);
      #endif
      if (wake_reason == 1){
        //woken up by interrupt on d3
        ir_received();
      }
      else{
        //woken by update_interval
        update_interval();
      }
    
    }
    
    void ir_received(){
      delay(100);
        if (irrecv.decode(&ircode)) {
          unsigned long ir_value = ircode.value;
          //if (ir_value == REPEAT) //if repeat-code: send last code
          //{
          //   ir_value = last_value;
          //}
          //else{ //if not: save new value as last value
          //  last_value = ir_value;
          //}
          #ifdef MY_OWN_DEBUG
          Serial.println(ir_value,HEX);
          #endif
          
          send(msgIrRecord.set(ir_value));
          
        }
        irrecv.resume(); // Receive the next value
    
        Serial.println("IR Processing done--------------------");
    }
    
    void update_interval()      
    {  
      #ifdef MY_OWN_DEBUG
      Serial.println("In loop");
      #endif
      // Read temperature & humidity from sensor.
      const float temperature = float( metric ? tempsensor.getCelsiusHundredths() : tempsensor.getFahrenheitHundredths() ) / 100.0;
      float roundedTemp = floorf(temperature * 10) / 10; //round temp down to 1 decimal
      const float humidity    = float( tempsensor.getHumidityBasisPoints() ) / 100.0;
      float roundedHum = floorf(humidity * 10) / 10; //round humidty down to 1 decimal
    
      lightmeter.configure(BH1750_ONE_TIME_HIGH_RES_MODE);
      //delay(500); // Allow some time
      const uint16_t lux = lightmeter.readLightLevel();
    
    
      if (lastHum != roundedHum){
          #ifdef MY_OWN_DEBUG
            Serial.print("roundedHum: ");Serial.println(roundedHum);
          #endif
        send(msgHum.set(roundedHum, 1));
        lastHum = roundedHum;
      }
    
      if (lastTemp != roundedTemp){
        send(msgTemp.set(temperature, 1));
        lastTemp = roundedTemp;
      }
    
      if (lastLux != lux){
        send(msgLux.set(lux, 1));
        lastLux = lux;
      }
    
      //send battery value
      battery();
    
    
    
    }
    
    void battery(){
         //omitted for brevity
    
    }
    
    // Dumps out the decode_results structure.
    void dump(decode_results *results) {
        int count = results->rawlen;
        unsigned long test = results->value;
        
        Serial.print("raw: ");
        Serial.print(test, HEX);
        Serial.println("");
        
        Serial.print(F("Received : "));
        Serial.print(results->decode_type, DEC);
        Serial.print(F(" "));
        Serial.print(Type2String(results->decode_type));
      
        if (results->decode_type == PANASONIC) {  
          Serial.print(AddrTxt);
          Serial.print(results->address,HEX);
          Serial.print(ValueTxt);
        }
        Serial.print(F(" "));
        Serial.print(results->value, HEX);
        Serial.print(F(" ("));
        Serial.print(results->bits, DEC);
        Serial.println(F(" bits)"));
      
        if (results->decode_type == UNKNOWN) {
          Serial.print(F("Raw ("));
          Serial.print(count, DEC);
          Serial.print(F("): "));
      
          for (int i = 0; i < count; i++) {
            if ((i % 2) == 1) {
              Serial.print(results->rawbuf[i]*USECPERTICK, DEC);
            } 
            else {
              Serial.print(-(int)results->rawbuf[i]*USECPERTICK, DEC);
            }
            Serial.print(" ");
          }
          Serial.println("");
        }
    }
    


  • Are you perhaps using a mqtt gateway and retained messages?



  • @kiesel said in IR Node resending last signal ca every 15 minutes:

    wake_reason = sleep(RECV_PIN-2, RISING, UPDATE_INTERVAL);

    How do you think this is working?

    From my experience this is not possible and you are actually putting the node to sleep. But of course I could be wrong (and often am). 😉



  • @electrik

    I am using a serial gateway, but long term plan is to use an mqtt gateway.



  • @skywatch

    I want to put the node to sleep. And it actually works very well, when it is woken up by a pin interrupt it reads the data and sends them to my serial gateway.

    The issue is that it repeats messages.

    I have now covered the sensor and I still get messages ca every 15 minutes.

    Is resending messages a part of the send()-function maybe?


  • Mod

    @kiesel getting a log of the serial output might be the quickest wayto troubleshoot. you already have nice serial prints that will describe what the node is doing.



  • @mfalkvidd

    I am a bit embarrassed that I didn't post them straight away. I'll collect a bit of data during the night and send the logs tomorrow. Thanks!



  • I had a look at the Home Assistant logs and I think I have been blaming the wrong beast, my code seems to be innocent.

    I use appdaemon to execute actions in/from Home Assistant. There I can see exactly when a "ghost"-update was received.

    Matching those timestamps with timestamps from the Home Assistant log was spot on:

    Appdaemon log:

    2020-03-11 09:38:23.092076 INFO Living_Room_IR: ir_value: 551505585
    2020-03-11 09:39:48.834817 INFO Living_Room_IR: ir_value: 551505585
    2020-03-11 09:48:03.398937 INFO Living_Room_IR: ir_value: 551505585
    2020-03-11 09:49:19.742706 INFO Living_Room_IR: ir_value: 551505585
    2020-03-11 10:05:24.735442 INFO Living_Room_IR: ir_value: 551505585
    2020-03-11 10:06:58.973448 INFO Living_Room_IR: ir_value: 551505585
    2020-03-11 10:38:26.141511 INFO Living_Room_IR: ir_value: 551505585
    2020-03-11 10:39:42.890820 INFO Living_Room_IR: ir_value: 551505585
    2020-03-11 10:47:59.874830 INFO Living_Room_IR: ir_value: 551505585
    2020-03-11 10:49:16.437996 INFO Living_Room_IR: ir_value: 551505585
    2020-03-11 11:15:23.592502 INFO Living_Room_IR: ir_value: 551505585
    2020-03-11 11:16:40.138025 INFO Living_Room_IR: ir_value: 551505585
    2020-03-11 11:18:05.195990 INFO Living_Room_IR: ir_value: 551505585
    2020-03-11 11:19:39.443632 INFO Living_Room_IR: ir_value: 551505585
    2020-03-11 12:27:05.469657 INFO Living_Room_IR: ir_value: 551505585
    2020-03-11 12:28:22.691106 INFO Living_Room_IR: ir_value: 551505585
    2020-03-11 12:35:15.985303 INFO Living_Room_IR: ir_value: 551505585
    2020-03-11 12:36:33.073911 INFO Living_Room_IR: ir_value: 551505585
    2020-03-11 12:40:29.881660 INFO Living_Room_IR: ir_value: 551505585
    2020-03-11 12:42:01.804079 INFO Living_Room_IR: ir_value: 551505585
    

    Here is the corresponding part of the home assistant log:

    {"log":"2020-03-11 09:38:22 DEBUG (MainThread) [homeassistant.components.mysensors.gateway] Node update: n
    ode 3 child 255\n","stream":"stderr","time":"2020-03-11T08:38:22.931537407Z"}
    {"log":"2020-03-11 09:39:48 DEBUG (MainThread) [homeassistant.components.mysensors.gateway] Node update: n
    ode 3 child 255\n","stream":"stderr","time":"2020-03-11T08:39:48.650792534Z"}
    {"log":"2020-03-11 09:48:03 DEBUG (MainThread) [homeassistant.components.mysensors.gateway] Node update: n
    ode 3 child 255\n","stream":"stderr","time":"2020-03-11T08:48:03.210220912Z"}
    {"log":"2020-03-11 09:49:19 DEBUG (MainThread) [homeassistant.components.mysensors.gateway] Node update: n
    ode 3 child 255\n","stream":"stderr","time":"2020-03-11T08:49:19.579932619Z"}
    {"log":"2020-03-11 10:05:24 DEBUG (MainThread) [homeassistant.components.mysensors.gateway] Node update: n
    ode 3 child 255\n","stream":"stderr","time":"2020-03-11T09:05:24.564205929Z"}
    {"log":"2020-03-11 10:06:58 DEBUG (MainThread) [homeassistant.components.mysensors.gateway] Node update: n
    ode 3 child 255\n","stream":"stderr","time":"2020-03-11T09:06:58.804235809Z"}
    {"log":"2020-03-11 10:38:25 DEBUG (MainThread) [homeassistant.components.mysensors.gateway] Node update: n
    ode 3 child 255\n","stream":"stderr","time":"2020-03-11T09:38:25.95710773Z"}
    {"log":"2020-03-11 10:39:42 DEBUG (MainThread) [homeassistant.components.mysensors.gateway] Node update: n
    ode 3 child 255\n","stream":"stderr","time":"2020-03-11T09:39:42.703318764Z"}
    {"log":"2020-03-11 10:47:59 DEBUG (MainThread) [homeassistant.components.mysensors.gateway] Node update: n
    ode 3 child 255\n","stream":"stderr","time":"2020-03-11T09:47:59.694853604Z"}
    {"log":"2020-03-11 10:49:16 DEBUG (MainThread) [homeassistant.components.mysensors.gateway] Node update: n
    ode 3 child 255\n","stream":"stderr","time":"2020-03-11T09:49:16.294815751Z"}
    {"log":"2020-03-11 11:15:23 DEBUG (MainThread) [homeassistant.components.mysensors.gateway] Node update: n
    ode 3 child 255\n","stream":"stderr","time":"2020-03-11T10:15:23.452517606Z"}
    {"log":"2020-03-11 11:16:39 DEBUG (MainThread) [homeassistant.components.mysensors.gateway] Node update: n
    ode 3 child 255\n","stream":"stderr","time":"2020-03-11T10:16:39.957885612Z"}
    {"log":"2020-03-11 11:18:05 DEBUG (MainThread) [homeassistant.components.mysensors.gateway] Node update: n
    ode 3 child 255\n","stream":"stderr","time":"2020-03-11T10:18:05.045447402Z"}
    {"log":"2020-03-11 11:19:39 DEBUG (MainThread) [homeassistant.components.mysensors.gateway] Node update: n
    ode 3 child 255\n","stream":"stderr","time":"2020-03-11T10:19:39.270413469Z"}
    {"log":"2020-03-11 12:27:05 DEBUG (MainThread) [homeassistant.components.mysensors.gateway] Node update: n
    ode 3 child 255\n","stream":"stderr","time":"2020-03-11T11:27:05.326243334Z"}
    {"log":"2020-03-11 12:28:22 DEBUG (MainThread) [homeassistant.components.mysensors.gateway] Node update: n
    ode 3 child 255\n","stream":"stderr","time":"2020-03-11T11:28:22.519338238Z"}
    {"log":"2020-03-11 12:35:15 DEBUG (MainThread) [homeassistant.components.mysensors.gateway] Node update: n
    ode 3 child 255\n","stream":"stderr","time":"2020-03-11T11:35:15.805191381Z"}
    {"log":"2020-03-11 12:36:32 DEBUG (MainThread) [homeassistant.components.mysensors.gateway] Node update: n
    ode 3 child 255\n","stream":"stderr","time":"2020-03-11T11:36:32.903939567Z"}
    {"log":"2020-03-11 12:40:29 DEBUG (MainThread) [homeassistant.components.mysensors.gateway] Node update: n
    ode 3 child 255\n","stream":"stderr","time":"2020-03-11T11:40:29.720752968Z"}
    {"log":"2020-03-11 12:42:01 DEBUG (MainThread) [homeassistant.components.mysensors.gateway] Node update: n
    ode 3 child 255\n","stream":"stderr","time":"2020-03-11T11:42:01.635196016Z"}
    

    So it seems that every time a Node update was triggered Home Assistant was told that there was a new value received from the IR-sensor.

    Here is the whole log from Home Assistant:

    {"log":"2020-03-11 12:42:00 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:11494641 TSF:MSG:RE
    AD,3-3-0,s=0,c=1,t=1,pt=7,l=5,sg=0:38.4\n","stream":"stderr","time":"2020-03-11T11:42:00.295978262Z"}
    {"log":"2020-03-11 12:42:00 DEBUG (MainThread) [homeassistant.components.mysensors.gateway] Node update: n
    ode 3 child 0\n","stream":"stderr","time":"2020-03-11T11:42:00.311538101Z"}
    {"log":"2020-03-11 12:42:00 DEBUG (MainThread) [homeassistant.components.mysensors.device] Entity update:
    mysensors_wohnzimmer_main 3 0: value_type 1, value = 38.4\n","stream":"stderr","time":"2020-03-11T11:42:00
    .415847867Z"}
    {"log":"2020-03-11 12:42:00 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:11495280 TSF:MSG:RE
    AD,3-3-0,s=2,c=1,t=37,pt=7,l=5,sg=0:45.0\n","stream":"stderr","time":"2020-03-11T11:42:00.93325235Z"}
    {"log":"2020-03-11 12:42:00 DEBUG (MainThread) [homeassistant.components.mysensors.gateway] Node update: n
    ode 3 child 2\n","stream":"stderr","time":"2020-03-11T11:42:00.950559479Z"}
    {"log":"2020-03-11 12:42:01 DEBUG (MainThread) [homeassistant.components.mysensors.device] Entity update:
    mysensors_wohnzimmer_main 3 2: value_type 37, value = 45.0\n","stream":"stderr","time":"2020-03-11T11:42:0
    1.058505324Z"}
    {"log":"2020-03-11 12:42:01 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:11495962 TSF:MSG:RE
    AD,3-3-0,s=255,c=3,t=0,pt=1,l=1,sg=0:22\n","stream":"stderr","time":"2020-03-11T11:42:01.618936799Z"}
    {"log":"2020-03-11 12:42:01 DEBUG (MainThread) [homeassistant.components.mysensors.gateway] Node update: n
    ode 3 child 255\n","stream":"stderr","time":"2020-03-11T11:42:01.635196016Z"}
    {"log":"2020-03-11 12:42:01 DEBUG (MainThread) [homeassistant.components.mysensors.device] Entity update:
    mysensors_wohnzimmer_main 3 0: value_type 1, value = 38.4\n","stream":"stderr","time":"2020-03-11T11:42:01
    .738527926Z"}
    {"log":"2020-03-11 12:42:01 DEBUG (MainThread) [homeassistant.components.mysensors.device] Entity update:
    mysensors_wohnzimmer_main 3 1: value_type 0, value = 22.4\n","stream":"stderr","time":"2020-03-11T11:42:01
    .743098362Z"}
    {"log":"2020-03-11 12:42:01 DEBUG (MainThread) [homeassistant.components.mysensors.device] Entity update:
    mysensors_wohnzimmer_main 3 3: value_type 50, value = 624502100\n","stream":"stderr","time":"2020-03-11T11
    :42:01.747319859Z"}
    {"log":"2020-03-11 12:42:01 DEBUG (MainThread) [homeassistant.components.mysensors.device] Entity update:
    mysensors_wohnzimmer_main 3 3: value_type 33, value = 551505585\n","stream":"stderr","time":"2020-03-11T11
    :42:01.748432047Z"}
    {"log":"2020-03-11 12:42:01 DEBUG (MainThread) [homeassistant.components.mysensors.device] Entity update:
    mysensors_wohnzimmer_main 3 2: value_type 37, value = 45.0\n","stream":"stderr","time":"2020-03-11T11:42:0
    1.752559045Z"}
    {"log":"2020-03-11 12:42:02 DEBUG (SyncWorker_3) [mysensors.persistence] Saving sensors to persistence fil
    e /config/mysensorsserial.json\n","stream":"stderr","time":"2020-03-11T11:42:02.441267303Z"}
    

    Does anybody have an idea how I can prevent these updates? Or should I continue this thread in the Home Assistant forum of mysensors?


  • Mod

    @kiesel Nice work. I am not familiar with Home Assistant but I can move this entire thread into the Home Assistant category if you want.



  • @mfalkvidd

    That would be great, thanks!


  • Mod

    @kiesel done!



  • I am working around the issue by sending a zero after every received ir_value, that way I can identify refreshes in home assistant/appdaemon

    send(msgIrRecord.set(ir_value));
    send(msgIrRecord.set(0));
    

    This is a very ugly workaround though, does anybody have areal fix?



  • @kiesel Have you tried to replace the sensor with a pull-up resistor?



  • @olka

    Sorry for the late reply, I have been busy with a few other sensors.

    Do you mean attach a pull-up resistor to the ir sensor? I haven't tried that, but from what I can see the problem isn't the sensor node, it's the integration that sends events when no event has been sent. The gateway log doesn't show a new message being received so I guess the node isn't to blame.



  • Is the update mechanism maybe triggered by another meessage coming from your node? e.g. temperature or battery update



  • @electrik

    These updates trigger the event:

    {"log":"2020-03-11 12:42:01 DEBUG (MainThread) [homeassistant.components.mysensors.gateway] Node update: n
    ode 3 child 255\n","stream":"stderr","time":"2020-03-11T11:42:01.635196016Z"}
    

    From what I can see these updates happen whether I trigger something on the node or not, unfortunately.



  • Those are battery reports. You should have a look at the update mechanism in appdaemon, maybe that is also responding on this event.

    Can you post the code of that? I don't have experience with it but interested if this can be useful for me also, instead of node-red for my automations.



  • @electrik

    Thanks, I'll have a look at those updates.

    Do you mean the code I am using for my appdaemon app? I got everything I use from here: https://github.com/eifinger/appdaemon-scripts

    This is much cleaner and easier to understand than my code, but let me know if you want it anyway 🙂


Log in to reply
 

Suggested Topics

  • 3
  • 5
  • 3
  • 6
  • 2
  • 6
  • 4
  • 9

193
Online

9.8k
Users

10.3k
Topics

106.7k
Posts