MySensors - Gateway to Domoticz

Subforum for the 'MySensors' project.
http://www.mysensors.org/
User avatar
gizmocuz
Posts: 8526
Joined: Thursday 11 July 2013 18:59
Target OS: Raspberry Pi
Domoticz version: beta
Location: Top of the world
Contact:

Re: MySensors - Gateway to Domoticz

Post by gizmocuz » Monday 23 November 2015 20:28

1.5 will also work... (because there was no fix for the heartbeat message, i had to test with this)
glad all is working

as examples for 1.6, the 1.6 version has lots of examples
Quality outlives Quantity!

User avatar
SQ9MDD
Posts: 34
Joined: Friday 04 September 2015 22:34
Target OS: Raspberry Pi
Domoticz version: beta
Location: Warsaw Poland
Contact:

Re: MySensors - Gateway to Domoticz

Post by SQ9MDD » Tuesday 24 November 2015 9:38

I have few devices with some inputs/outpus and setpoints.
To easy find, configure, my proper device i'm sending device addres and child sensor id as name in the presence.
for example:

Code: Select all

53.AI1
53.AI2
53.BI1
53.BI2
53.BO1
53.BO2
I can see this in child list but from setup->devices i can't see my name. I saw this before but not in the latest beta.
This is a simple way to identify many of sensors, is dificoult to understand this ID,IDX and unit stuff from devices.
But proper name can tell you all, address of device and sensor.

Is any chance to get this work?
Attachments
devices-list.jpg
devices-list.jpg (88.12 KiB) Viewed 3522 times
child-list.jpg
child-list.jpg (74.3 KiB) Viewed 3522 times

User avatar
gizmocuz
Posts: 8526
Joined: Thursday 11 July 2013 18:59
Target OS: Raspberry Pi
Domoticz version: beta
Location: Top of the world
Contact:

Re: MySensors - Gateway to Domoticz

Post by gizmocuz » Tuesday 24 November 2015 10:46

Could you send me a PM with your sketch ?
I was expecting also that new sensors would have been created with the correct names, put a lot of effort into this....
Quality outlives Quantity!

User avatar
SQ9MDD
Posts: 34
Joined: Friday 04 September 2015 22:34
Target OS: Raspberry Pi
Domoticz version: beta
Location: Warsaw Poland
Contact:

Re: MySensors - Gateway to Domoticz

Post by SQ9MDD » Thursday 26 November 2015 9:40

Many thanx Gizmocuz, now is correct ;)
All devices are correct names.

Great job!
Attachments
solved.png
solved.png (74.2 KiB) Viewed 3461 times

socket
Posts: 1
Joined: Thursday 10 December 2015 23:50
Target OS: Raspberry Pi
Domoticz version: 2.3774
Location: Gliwice
Contact:

Re: MySensors - Gateway to Domoticz

Post by socket » Thursday 10 December 2015 23:56

Hi Gizmocuz,

First of all you are doing here great job! Do you have maybe the similar code uses the eprom memory to load/save the pulsecount for EnergyMeter ?

http://www.mysensors.org/build/pulse_power

I am trying also update the current total value KWH usage ("Data" : "1.048 kWh") according to the physical EnergyMeter where total=12834 KWH. I was trying something like that without success:

/json.htm?type=command&param=updateuservariable&idx=97&vname=MySensEnergyMeter&vtype=0&vvalue=12834
/json.htm?type=command&param=updateuservariable&rid=97&vname=Usage&vtype=1&vvalue=12834000
/json.htm?type=command&param=udevice&idx=97&nvalue=0&svalue=400;12834

{
"AddjMulti" : 1.0,
"AddjMulti2" : 1.0,
"AddjValue" : 0.0,
"AddjValue2" : 0.0,
"BatteryLevel" : 255,
"CounterToday" : "0.381 kWh",
"CustomImage" : 0,
"Data" : "0.518 kWh",
"Description" : "",
"Favorite" : 0,
"HardwareID" : 21,
"HardwareName" : "MySensorsUSB",
"HardwareType" : "MySensors Gateway USB",
"HardwareTypeVal" : 41,
"HaveTimeout" : false,
"ID" : "00000101",
"LastUpdate" : "2015-12-11 00:40:12",
"Name" : "MySensEnergyMeter",
"Notifications" : "false",
"PlanID" : "0",
"PlanIDs" : [ 0 ],
"Protected" : false,
"ShowNotifications" : true,
"SignalLevel" : "-",
"SubType" : "kWh",
"SwitchTypeVal" : 0,
"Timers" : "false",
"Type" : "General",
"TypeImg" : "current",
"Unit" : 1,
"Usage" : "463.0 Watt",
"Used" : 1,
"XOffset" : "0",
"YOffset" : "0",
"idx" : "97"
}


Thanks in advance!
gizmocuz wrote:
ThinkPad wrote:I think i am already seeing that. Connected 'MYSController' to the Ethernet gateway i made, and i see the application constantly scrolling, only thing it displays is:

RECV REQ VAR1

Nice, looking forward to it! Let us know if we can help in any way :)
Below the new code, it also uses the eprom memory to load/save the pulsecount, which is much better then requesting this from the host software (domoticz),
in case its down for whatever reason ;)

A new beta is building at the moment (will take at least 15 minutes), please let us know if you got it working !

Code: Select all

//
// Use this sensor to measure volume and flow of your house watermeter.
// You need to set the correct pulsefactor of your meter (pulses per m3).
// The sensor starts by reading the pulse count reading from the eprom.
// Reports both volume and flow 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 flow.
//

#include <SPI.h>
#include <MySensor.h>  

#define DIGITAL_INPUT_SENSOR 3                  // The digital input you attached your sensor.  (Only 2 and 3 generates interrupt!)

#define PULSE_FACTOR 1000                       // Nummber of blinks per m3 of your meter (One rotation/liter)

#define SLEEP_MODE false                        // flowvalue can only be reported when sleep mode is false.

#define MAX_FLOW 40                             // Max flow (l/min) value to report. This filters outliers.

#define CHILD_ID 1                              // Id of the sensor child

unsigned long SEND_FREQUENCY = 20000;           // Minimum time between send (in milliseconds). We don't want to spam the gateway.

#define EPROM_PULSECOUNT_1_STATE 1
#define EPROM_PULSECOUNT_2_STATE 2
#define EPROM_PULSECOUNT_3_STATE 3
#define EPROM_PULSECOUNT_4_STATE 4

MySensor gw;
MyMessage flowMsg(CHILD_ID,V_FLOW);
MyMessage volumeMsg(CHILD_ID,V_VOLUME);
 
double ppl = ((double)PULSE_FACTOR)/1000;        // Pulses per liter

volatile unsigned long pulseCount = 0;   
volatile unsigned long lastBlink = 0;
volatile double flow = 0;  
boolean pcReceived = false;
unsigned long oldPulseCount = 0;
unsigned long newBlink = 0;   
double oldflow = 0;
double volume;                     
double oldvolume;
unsigned long lastSend;
unsigned long lastPulse;
unsigned long currentTime;
boolean metric;

void setup()  
{  
  gw.begin(); 

  // Send the sketch version information to the gateway and Controller
  gw.sendSketchInfo("Water Meter", "1.1");

  // Register this device as Waterflow sensor
  gw.present(CHILD_ID, S_WATER);       

  //Retreive our last pulse count value from the eprom
  pulseCount = oldPulseCount = LoadLastPulseCount();

  lastSend = millis();

  attachInterrupt(1, onPulse, RISING);
}


void loop()     
{ 
  gw.process();
  currentTime = millis();
	
    // Only send values at a maximum frequency or woken up from sleep
  bool sendTime = (currentTime - lastSend) > SEND_FREQUENCY;
  if (SLEEP_MODE || sendTime)
  {
    lastSend=currentTime;

    if (!SLEEP_MODE && flow != oldflow) {
      oldflow = flow;

      //Serial.print("l/min:");
      //Serial.println(flow);

      // Check that we dont get unresonable large flow value. 
      // could hapen when long wraps or false interrupt triggered
      if (flow<((unsigned long)MAX_FLOW)) {
        gw.send(flowMsg.set(flow, 2));                   // Send flow value to gw
      }  
    }
  
    // No Pulse count in 2min 
    if(currentTime - lastPulse > 120000){
      flow = 0;
    } 

    // Pulse count has changed
    if (pulseCount != oldPulseCount) {
      oldPulseCount = pulseCount;
      SaveLastPulseCount(pulseCount);
      
      //Serial.print("pulsecount:");
      //Serial.println(pulseCount);

      double volume = ((double)pulseCount/((double)PULSE_FACTOR));     
      if (volume != oldvolume) {
        //Serial.print("volume:");
        //Serial.println(volume, 3);
        
        gw.send(volumeMsg.set(volume, 3));               // Send volume value to gw
        oldvolume = volume;
      } 
    }
  }
  if (SLEEP_MODE) {
    gw.sleep(SEND_FREQUENCY);
  }
}

unsigned long LoadLastPulseCount()
{
    int PCount_1=gw.loadState(EPROM_PULSECOUNT_1_STATE); 
    int PCount_2=gw.loadState(EPROM_PULSECOUNT_2_STATE); 
    int PCount_3=gw.loadState(EPROM_PULSECOUNT_3_STATE); 
    int PCount_4=gw.loadState(EPROM_PULSECOUNT_4_STATE); 

    //check if valid
    if ((PCount_1==0xFF)&&(PCount_2==0xFF)&&(PCount_3==0xFF)&&(PCount_4==0xFF))
      return 0;//never saved before
    unsigned long PulseCount=(PCount_1<<24)|(PCount_2<<16)|(PCount_3<<8)|PCount_4;
    //Serial.print("Last Pulsecount: ");
    //Serial.println(PulseCount);
    return PulseCount;
}

void SaveLastPulseCount(unsigned long PulseCount)
{
    int PCount_1=(PulseCount&0xFF000000)>>24; 
    int PCount_2=(PulseCount&0xFF0000)>>16; 
    int PCount_3=(PulseCount&0xFF00)>>8; 
    int PCount_4=PulseCount&0xFF; 

    gw.saveState(EPROM_PULSECOUNT_1_STATE, PCount_1); 
    gw.saveState(EPROM_PULSECOUNT_2_STATE, PCount_2); 
    gw.saveState(EPROM_PULSECOUNT_3_STATE, PCount_3); 
    gw.saveState(EPROM_PULSECOUNT_4_STATE, PCount_4); 
}

void onPulse()     
{
  if (!SLEEP_MODE)
  {
    unsigned long newBlink = micros();   
    unsigned long interval = newBlink-lastBlink;
    
    if (interval!=0)
    {
      lastPulse = millis();
      if (interval<500000L) {
        // Sometimes we get interrupt on RISING,  500000 = 0.5sek debounce ( max 120 l/min)
        return;   
      }
      flow = (60000000.0 /interval) / ppl;
    }
    lastBlink = newBlink;
  }
  pulseCount++; 
}

shkaff
Posts: 24
Joined: Friday 11 December 2015 11:29
Target OS: Raspberry Pi
Domoticz version: Stable
Contact:

Re: MySensors - Gateway to Domoticz

Post by shkaff » Friday 11 December 2015 12:52

hansrune wrote:For the connection question : Connection is to the Arduino via a serial USB interface.

As for RFXcom devices, it is convenient to make a persistent device name that Domoticz can read and write also for the MySensors gateway connection. Use the lsusb command to display the vendor and product id, then use these as in the following udev rule example.

Here is my /etc/udev/rules.d/71-mysensors.rules. Domoticz will find the Mysensors serial gateway via ttyUSB31

Code: Select all

#
#  idVendor           0x1a86 QinHeng Electronics
#  idProduct          0x7523 HL-340 USB-Serial adapter
#
SUBSYSTEM=="tty", ATTRS{idVendor}=="1a86", ATTRS{idProduct}=="7523", SYMLINK+="ttyUSB31", MODE="0666", SYMLINK+="mysensors"
#
# Tests:
# udevadm info --query=all --name ttyUSB0
# udevadm test $(udevadm info --query path --name ttyUSB0 )
#
Is it still actual guidance to get USB based SerialGateway properly set up and recognized at Domoticz?
I just started playing with, and I can see that the system offers specifying manually which Serial Port is to use.
Setup->Hardware->Add
  • Type: MySensors Gateway USB
  • Serial Port: /dev/ttyUSB0
I mean it looks no need to play with idVendor and idProduct anymore. Not sure also because of messing well guide how to start with MySensors and Domoticz together.

fets
Posts: 25
Joined: Monday 21 September 2015 20:10
Target OS: Raspberry Pi
Domoticz version: 2.2969
Contact:

Re: MySensors - Gateway to Domoticz

Post by fets » Wednesday 23 December 2015 23:33

Hello,
Since several version, I experienced a strange behaviour using domoticz : some messages sent by my node seemed ignored.
First I have to tell that some msg sent by my node requieres an acknowledge.
So I read sources from domoticz repository and I think I understand what happens.
In file MySensorBase.cpp, method MySensorsBase::ParseLine and line 1566

Code: Select all

		if (ack == 1)
		{
			//No need to process ack commands
			return;
		}
That means that all incoming messages asking for ack are ignored !!!

Is this behavior wanted or is this an issue ?

User avatar
gizmocuz
Posts: 8526
Joined: Thursday 11 July 2013 18:59
Target OS: Raspberry Pi
Domoticz version: beta
Location: Top of the world
Contact:

Re: MySensors - Gateway to Domoticz

Post by gizmocuz » Wednesday 30 December 2015 1:23

The acknowledge should be send by the gateway and not by the controller (software application) or did I miss something?
Quality outlives Quantity!

andriej
Posts: 302
Joined: Tuesday 10 December 2013 23:27
Target OS: Linux
Domoticz version: beta
Contact:

Re: MySensors - Gateway to Domoticz

Post by andriej » Wednesday 30 December 2015 1:26

Doesn't the application could doublechecked it did and got response back and -if not - print an error?
Orange Pi (@ Debian) / MySensors Serial / GPIO / Custom Serial 433 MHz Transmitter (for plug switches and livolo wall switches) / JSON&Bash API scripts

fets
Posts: 25
Joined: Monday 21 September 2015 20:10
Target OS: Raspberry Pi
Domoticz version: 2.2969
Contact:

Re: MySensors - Gateway to Domoticz

Post by fets » Wednesday 30 December 2015 22:44

gizmocuz wrote:The acknowledge should be send by the gateway and not by the controller (software application) or did I miss something?
Maybe your right, I'll check on mysensors sources later.

But anyway the message should be processed by domoticz in order to update status?
I downloaded domoticz sources commented lines I mentionned earlier and regenerate.
And now, everything works as expected :D.
Do you plan to something to my issue ?

fets
Posts: 25
Joined: Monday 21 September 2015 20:10
Target OS: Raspberry Pi
Domoticz version: 2.2969
Contact:

Re: MySensors - Gateway to Domoticz

Post by fets » Wednesday 30 December 2015 22:49

fets wrote:I'll check on mysensors sources later.
So I checked and you are totally right

User avatar
gizmocuz
Posts: 8526
Joined: Thursday 11 July 2013 18:59
Target OS: Raspberry Pi
Domoticz version: beta
Location: Top of the world
Contact:

Re: MySensors - Gateway to Domoticz

Post by gizmocuz » Saturday 02 January 2016 4:11

Does this mean all should work fine without your patch?
Quality outlives Quantity!

fets
Posts: 25
Joined: Monday 21 September 2015 20:10
Target OS: Raspberry Pi
Domoticz version: 2.2969
Contact:

Re: MySensors - Gateway to Domoticz

Post by fets » Saturday 02 January 2016 11:21

gizmocuz wrote:Does this mean all should work fine without your patch?
No, my patch is necessary to manage incoming message with ack request (we agree that the answer was sent abck by gateway).
In order to update sensor status in domoticz, the message must be processed further.

andriej
Posts: 302
Joined: Tuesday 10 December 2013 23:27
Target OS: Linux
Domoticz version: beta
Contact:

Re: MySensors - Gateway to Domoticz

Post by andriej » Saturday 02 January 2016 11:28

And it would be also nice to notify that incoming message from MySensors is with ACK.
Orange Pi (@ Debian) / MySensors Serial / GPIO / Custom Serial 433 MHz Transmitter (for plug switches and livolo wall switches) / JSON&Bash API scripts

fets
Posts: 25
Joined: Monday 21 September 2015 20:10
Target OS: Raspberry Pi
Domoticz version: 2.2969
Contact:

Re: MySensors - Gateway to Domoticz

Post by fets » Saturday 02 January 2016 11:46

andriej wrote:And it would be also nice to notify that incoming message from MySensors is with ACK.
notify to who or how ?

andriej
Posts: 302
Joined: Tuesday 10 December 2013 23:27
Target OS: Linux
Domoticz version: beta
Contact:

Re: MySensors - Gateway to Domoticz

Post by andriej » Saturday 02 January 2016 16:34

In messages/status list. :-)
Its already showing that domoticz got message. There could be another character or other indicator showing that it's ack message.
Orange Pi (@ Debian) / MySensors Serial / GPIO / Custom Serial 433 MHz Transmitter (for plug switches and livolo wall switches) / JSON&Bash API scripts

fets
Posts: 25
Joined: Monday 21 September 2015 20:10
Target OS: Raspberry Pi
Domoticz version: 2.2969
Contact:

Re: MySensors - Gateway to Domoticz

Post by fets » Friday 08 January 2016 22:04

@gizmocuz any news on my ack issue ?

I just create a pull request on this subject. I never used git so this is my first PR.
I hope I did the right thing

User avatar
Derik
Posts: 1890
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: MySensors - Gateway to Domoticz

Post by Derik » Sunday 10 January 2016 13:07

I have 2 x Arduino Uno to test.
I have the Gateway, visible in domotcz with the firmware version. [So I assume this is true.]
ScreenShot010.jpg
ScreenShot010.jpg (8.59 KiB) Viewed 2830 times
I have the ip and port adapted in the sketch. this also in the Domoticz.[ changed ip-port and mac, and activate the w5100 ]
ScreenShot012.jpg
ScreenShot012.jpg (89.37 KiB) Viewed 2830 times
I checked the cables 3x, also of the nRF24L01 +.
And I set on new hardware, in domoticz.
I see movement of LEDs on the uno ..

I have a uno a pir and the NRF. The pir on 5volt pin. [NRF24L01 + on the 3.3Volt]
I have the software sketch from mysensors directly into my uno shot
I checked the wires 3 x.

I see domoticz no node sensor or whatever.
ScreenShot011.jpg
ScreenShot011.jpg (86.23 KiB) Viewed 2830 times
I see on the uno with the pir no movement ...

What am I doing wrong?
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups

User avatar
Mediacj
Posts: 97
Joined: Wednesday 11 February 2015 17:09
Target OS: Raspberry Pi
Domoticz version:
Location: Netherlands
Contact:

Re: MySensors - Gateway to Domoticz

Post by Mediacj » Sunday 10 January 2016 14:49

Did you use a capacitor on the radio?

What is displayed in the serial monitor of one of your sensors? Do you see errors or?

User avatar
Derik
Posts: 1890
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: MySensors - Gateway to Domoticz

Post by Derik » Sunday 10 January 2016 19:55

Mediacj wrote:Did you use a capacitor on the radio?
Shame :oops: no...
Mediacj wrote:What is displayed in the serial monitor of one of your sensors? Do you see errors or?
There are errors in the serial monitor when i ulpoad from the Codebender Browser Plugin


Edit:

What is the capacity of this capacitor ?
I have 470 uf 16 volt?
Is that a good one?
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest