Only get values from one channel (have two channels)

Discussion about Z-Uno product. Visit http://z-uno.z-wave.me for more details.
Post Reply
splitfile
Posts: 2
Joined: 11 Jul 2019 14:04

Only get values from one channel (have two channels)

Post by splitfile » 11 Jul 2019 14:16

Hi,

I'm trying to get the Zuno to work as a sensor with two channels. The sensor reports back power values. Watts and KWh (Kilo watt hours).
The problem is that I seem to only get values on one channel.

Maybe I'm not setting the channels up correctly? I read something about some issue if you have two channels with the same type?

All help appreciated :-)

Code: Select all

#define DEBUG       1
 
// LED pin number
#define LED_PIN     13

// button pin number
#define BTN_PIN     18

// channel number
#define ZUNO_CHANNEL_NUMBER_ONE   1
#define ZUNO_CHANNEL_NUMBER_TWO   2

// Number of blinks per kWh of your meter
#define PULSE_FACTOR 1000

// Pulses per watt hour
float ppwh = ((float)PULSE_FACTOR)/1000;

// The value to report back to controller
//unsigned int kWh;

// Counting the light pulse
volatile uint32_t pulseCount = 0;

volatile uint32_t lastBlink = 0;

volatile uint32_t watt = 0;
volatile uint32_t watt_dummy = 0;

// next macro sets up the Z-Uno channels
// you can read more on http://z-uno.z-wave.me/Reference/ZUNO_SENSOR_BINARY/

ZUNO_SETUP_CHANNELS(
      // CHANNEL 1
      ZUNO_METER(ZUNO_METER_TYPE_ELECTRIC,
                 METER_RESET_ENABLE,
                 ZUNO_METER_ELECTRIC_SCALE_KWH,  
                 METER_SIZE_FOUR_BYTES, 
                 METER_PRECISION_ZERO_DECIMALS, 
                 get_kwh,
                 reset_kwh
      ),
      // CHANNEL 2
      ZUNO_METER(ZUNO_METER_TYPE_ELECTRIC,
                 METER_RESET_ENABLE,
                 ZUNO_METER_ELECTRIC_SCALE_WATTS,  
                 METER_SIZE_FOUR_BYTES, 
                 METER_PRECISION_ZERO_DECIMALS, 
                 get_watt,
                 reset_watt
      )
);

// Set the interrupt callback function
ZUNO_SETUP_ISR_INT0(onPulse);



void setup() 
{
  // Enable interrupt. Triggered when light pulse is detected
  zunoExtIntMode(ZUNO_EXT_INT0, RISING);
}

void loop()
{
#ifdef DEBUG
  Serial.println("Sending on channel 1");
#endif
  zunoSendReport(ZUNO_CHANNEL_NUMBER_ONE); // send report over the Z-Wave to the controller

#ifdef DEBUG
  Serial.println("Sending on channel 2");
#endif
  zunoSendReport(ZUNO_CHANNEL_NUMBER_TWO); // send report over the Z-Wave to the controller

  delay(35000); //sleep 35s
}


// function, which returns the previously saved button state
// this function runs only once the controller asks
uint32_t get_kwh()
{
#ifdef DEBUG
  Serial.print("get_kwh called, returned ");
  Serial.println(watt, DEC);
#endif

  // just return the pulseCount as a debug value
  return pulseCount;
}


void reset_kwh()
{
  Serial.println("reset_kwh() called");
}


void onPulse()
{
  #ifdef DEBUG
    Serial.println("onPulse! - Light pulse detected");
  #endif

  uint32_t newBlink = millis();
  uint32_t interval = newBlink - lastBlink;
  #ifdef DEBUG
    Serial.print("newBlink(");
    Serial.print(newBlink, DEC);
    Serial.print(") - lastblink(");
    Serial.print(lastBlink, DEC);
    Serial.print(") = interval(");
    Serial.print(interval, DEC);
    Serial.println(")");
  #endif
  
   watt = (3600000.0 / interval) / ppwh;
   lastBlink = newBlink;

  pulseCount++;

#ifdef DEBUG
  Serial.print("Count:");
  Serial.println(pulseCount, DEC);
  Serial.print("onPulse! - watt:");
  Serial.println(watt, 3);
#endif
}

uint32_t get_watt()
{
  watt_dummy++;
  #ifdef DEBUG
    Serial.print("get_watt called, returned ");
    Serial.println(watt_dummy, DEC);
  #endif
  return watt_dummy;
}

void reset_watt()
{
}

User avatar
PoltoS
Posts: 4722
Joined: 26 Jan 2011 19:36

Re: Only get values from one channel (have two channels)

Post by PoltoS » 15 Jul 2019 09:40

What is your controller?

rkv
Posts: 1
Joined: 15 Jul 2019 13:13

Re: Only get values from one channel (have two channels)

Post by rkv » 15 Jul 2019 13:25

There are no problems. Code works fine with Razberry.
Attachments
homeautomation_screenshot.png
homeautomation_screenshot.png (78.48 KiB) Viewed 63 times

splitfile
Posts: 2
Joined: 11 Jul 2019 14:04

Re: Only get values from one channel (have two channels)

Post by splitfile » 17 Jul 2019 18:09

Hi guys,

Thanks for your response!

I'm using Domoticz and a "Aeotec by Aeon Labs Z-Stick" -USB controller.

I think I got it to work setting up the channels like this:

Code: Select all

ZUNO_SETUP_CHANNELS(
  ZUNO_SENSOR_MULTILEVEL(ZUNO_SENSOR_MULTILEVEL_TYPE_POWER, 
                         SENSOR_MULTILEVEL_SCALE_WATT, 
                         SENSOR_MULTILEVEL_SIZE_TWO_BYTES, 
                         SENSOR_MULTILEVEL_PRECISION_ZERO_DECIMALS, 
                         get_watt),
  ZUNO_METER(ZUNO_METER_TYPE_ELECTRIC, 
             METER_RESET_ENABLE,
             ZUNO_METER_ELECTRIC_SCALE_KWH,
             METER_SIZE_FOUR_BYTES,
             METER_PRECISION_TWO_DECIMALS,
             get_kwh,
             reset_kwh)
);
Did you do it in another way?

Best regards!

User avatar
PoltoS
Posts: 4722
Joined: 26 Jan 2011 19:36

Re: Only get values from one channel (have two channels)

Post by PoltoS » 18 Jul 2019 03:17

Looks like a Domoticz bug that they do not recognize meters in channels without a special template. You "hacked" it by making one as sensor. Good job!

Post Reply