Directory of RSS feeds
Statistics

RSS feeds in the directory: 374

Added today: 0

Added yesterday: 0

Hi-Tech / Hardware

Create your device class to MajorDoMo

Samopal.pro 27.06.2019 at 05:24

So I riveted a bunch of controllers with MySensors and plugged them into MajorDoMo via the gateway. This article is about how to live with it. After all, to connect to MajorDoMo with each device has to perform many actions: create objects and connect them to the sensors Mysensors, configure processing of incoming values, the display on the screen forms (plans, scenes), reporting sensors.

To connect devices Mysensor to MajorDoMo, I see two ways:

to take Maximum advantage of what we have. That is, to attach all the sensors that are connected to the system, to existing classes of the system, and continue to cling to their scenes, forms, graphs, and scenarios. To create a hierarchy of classes corresponding to my devices as much as possible to lay them in the logic and display the data and have to cling to all the sensors connected to them.

still I went on the first path, except a little expanded existing classes. As a result, I received a huge number of similar objects (because every sensor of my device, which I get from 2 to 10, you need to create a separate object of the corresponding class)

had to reinstall MajorDoMo (for some reason when you call the scenes I used to love the Apache c 100% CPU load), and along with this I decided to restore order in the classroom.

the Task

Requires to simplify connection of a large number of similar soil moisture sensors. All sensors are battery powered and give three options. Battery voltage, ADC value, which can be converted to soil moisture and temperature from a single DS18B20 sensor that can be installed in the device.

the Preparatory stage. Creating base classes

To begin, create a base class SMyVccDevices for all my battery powered devices.

Then I create common properties for all battery devices:

Name — the device name that will be displayed in reports and forms Vcc — supply voltage, V — the key value with storing history in database VccMin and VccMax — values are needed for calculation of battery status VccText — test message about the battery status

Further vccUpdated create a method that will fire when you change the properties of Vcc

This method calculates the voltage of the battery in percent, forms the status of the battery of the records in VccText, and also writes the current time the property is updated and runs the parent class method setUpdatedText

// Change the time

$this->setProperty('updated', time());

$this->callMethodSafe('setUpdatedText');

// Read values

$min = $this->getProperty('VccMin');

if( $min == " || $min getProperty('VccMax');

if( $max == " || $max getProperty('Vcc');

// calculate the voltage in percent

$proc = 0;

if( $vcc > $max )$proc = 100;

else if( $vcc < $min )$proc = 0;

else if( $min == $max )$proc = 0;

else $proc = ($vcc - $min)/($max - $min)*100;

// Write battery status

if( $proc > 50 )$text = 'Battery normal';

else if( $proc > 10 )$text = 'battery Low';

else $text = 'Critical battery';

// Write the value of properties

$this->setProperty('VccText',$text);

Class SMyVccDevices ready. Now you can create device-specific classes inheriting this class. Next, create a class of measurement devices temperature humidity SMyTempHumDevices. Allocations in this class can be useful for sensors with DHT22, HTU21D procima and thermo-hygrometers.

this class will create two key properties with the storage of history values:

Temp — Hum temperature — relative humidity

Private methods in this class no

the establishment of the class of my device

Now the actual class for a resistive device measuring the relative humidity of the soil.

he will Have two additional properties:

HumADC — values the ADC controller, which will bind directly to the sensor HymText — text field moisture estimates for reports and forms

And the method humUpdated, is bound to change the properties HumADC. The algorithm of recalculation of values I'll still leave

$adc = $this->getProperty('HumADC');

$new_value = 0.000001*$adc*$adc*$adc*-1;

$new_value += $adc*$adc*0.001649;

$new_value += $adc*-0.686978;

$new_value += 121.559157;

$new_value = round($new_value,1);

if( $new_value > 100 )$new_value = 100;

$this->setProperty('Hum',$new_value);

if( $new_value == " || $new_value setProperty('HumText','No data');

else if( $new_value < 40 )

$this->setProperty('HumText','Need watering');

else if( $new_value < 50 )

$this->setProperty('HumText','Soon watering');

else if( $new_value < 75 )

$this->setProperty('HumText','normal');

else $this->setProperty('HumText','Very wet');

For this class will create the display template — the form, how objects of a given class will be shown on the plans and scenes MajorDoMo

I prefer a table display all values in one line

%.Name%

%.Temp%

%.Hum%

%.Vcc%

%.HumText%

Poll: %.updatedText%

That's all. Now we need to create the required number of objects of class SMyRSoilDevices

and manually fill in their Name property, VccMin and VccMax

Left to tie the MySensors device with the created objects

To create a scene with all of the humidity sensors, it is sufficient to distribute the elements of type "object" and select the newly created objects

Well, for convenience, create the following script sends a report about the moisture on e-mail:

require_once 'lib/PHPMailer/PHPMailerAutoload.php';

$mail = new PHPMailer;

$mail->setLanguage('EN', 'lib/PHPMailer/language/');

$mail->isSMTP();

//Enable SMTP debugging

// 0 = off (for production use)

// 1 = client messages

// 2 = client and server messages

$mail->SMTPDebug = 0;

$mail->Debugoutput = 'html';

$mail->Host = 'smtp.yandex.com';

//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission

$mail->Port = 587;

//Set the encryption system to use - ssl (deprecated) or tls

$mail->SMTPSecure = 'tls';

$mail->SMTPAuth = true;

$mail->CharSet = "UTF-8";

$mail->Username = 'User';

$mail->Password ='Password';

$mail->setFrom('From', 'SmartHome');

$mail->addAddress('Address', ");

$subj='Daily report of soil moisture of plants';

$mail->Subject = $subj;

global $wat,$bat,$err,$body,$body1,$body2,$body3;

$wat = 0;

$bat = 0;

$err = 0;

$body = ";

$body1 = ";

$body2 = ";

$body3 = ";

ReportSoil1('Soil72');

ReportSoil1('Soil73');

ReportSoil1('Soil74');

ReportSoil1('Soil75');

ReportSoil1('Soil76');

ReportSoil1('Soil77');

ReportSoil1('Soil78');

ReportSoil1('Soil79');

ReportSoil1('Soil80');

ReportSoil1('Soil81');

$body_all = 'Required watering: '.$wat.' '.$body1."\n\n\n";

$body_all = $body_all.'Battery: '.$bat.' '.$body2."\n\n\n";

$body_all = $body_all.'There is no connection: '.$err.' '.$body3."\n\n\n";

$body_all = $body_all."Full report:\n".$body ;

if( $wat > 0 )say('Required watering: '.$wat.' '.$body1);

if( $bat > 0 )say('Battery: '.$bat.' '.$body2);

if( $err > 0 )say('No connection: '.$err.' '.$body3);

$mail->Body = $body_all;

if (!$mail->send()) {

say( "mail Error:" . $mail->ErrorInfo);

} else {

say( "Report on the humidity of the mail sent!");

}

/**

* generation of a report for a single sensor

*/

ReportSoil1 function($soil){

global $body, $body1, $body2, $body3, $wat, $bat, $err;

// Inspection of the irrigation

if( gg($soil.'.HumText') == 'Needed watering' ){

if( $wat != 0 ) $body1 = $body1.', ';

$body1 = $body1.gg($soil.'.Name');

$wat++;

}

// Check battery charge

if( gg($soil.'.VccText') == 'Critical battery' ){

if( $bat != 0 ) $body2 = $body2.', ';

$body2 = $body2.gg($soil.'.Name');

$bat++;

}

// Check that the sensor is alive

if( time() - gg($soil.'.updated') > 18000 ){

if( $err != 0 ) $body3 = $body3.', ';

$body3 = $body3.gg($soil.'.Name');

$err++;

}

// Filling the main report

$body = $body."\n".gg($soil.'.Name').': ';

$body = $body.gg($soil.'.Hum');

$body = $body.'% ('.gg($soil.'.HumText').' )';

$body = $body.', baht:'.gg($soil.'.Vcc');

$body = $body.' ('.gg($soil.'.VccText').' )';

$body = $body.', '.gg($soil.'.updatedText');

}

as a result of running this script daily mail comes a report

Requires watering: 1 [74] Chlorophytum (kitchen)

Battery: 0

No connection: 1 [72] Dracaena

Full report:

[72] Dracaena: % ( ), bath: ( ),

[73] Monstera: 63.9% (OK ), bat:3.79 (Low battery ), 4 mins ago

[74] Chlorophytum (kitchen): 37.6% (Need watering ), bat:2.85 (Battery OK ), 1 mins ago

[75] Spurge: 100% (Very humid ), bat:2.91 (Battery OK ), 02:31

[76] Ficus benjamina: 100% (Very humid ), bat:2.89 (Battery OK ), 2 mins ago

[77] Jade: 69.5% (normal ), bat:2.95 (Battery OK ), 4 mins ago

[78] Ivy: 78% (Very humid ), bat:2.41 (Low battery ), 51 sec. ago

[79] Dracaena (red): 81.7% (Very humid ), bat:3.01 (Battery OK ), 4 mins ago

[80] Scheffler: 100% (Very humid ), bat:2.79 (Battery OK ), 4 mins ago

[81] Cissus (grape): 88.1% (Very humid ), bat:2.97 (Battery OK ), 2 mins ago

This article is written more as a reminder to yourself, but if someone will help to understand, I would be very happy

The post the Creation of a class of devices in the MajorDoMo appeared first on homemade.pro.

Other feed items

Universal watchdog timer ATtiny13 04.04.2019 at 16:58

Connect soil moisture sensors to MajorDoMo 26.01.2019 at 07:01