Automation Light Level

9 years 6 months ago #1215 by osalval
I'm trying to control Roller Shutter. The driver helper is easy to manage but read value of sensor not:

/*
This code is running one time when program is enabled
*/
int UmbralON = 520; // Umbral de desactivación
int UmbralOFF = 420; // Umbral de activación

public void Setup()
{
}

/*
This code is running periodicaly when program is enabled.
Cron job detirmine running period.
*/
public void Run()
{
ModuleParameter L = ModuleHelper.GetProperty(Domains.MYSENSORS, "N23S1", "Sensor.LightLevel");

// Luz Persiana ALTA
if (L != null && L > UmbralON) {
DriverHelper.ProcessCommad(Domains.MYSENSORS, "N23S0", "ControlDown", "1");
}
// Luz Persiana NORMAL
if (L != null && L <= UmbralON && L >= UmbralOFF){
DriverHelper.ProcessCommad(Domains.MYSENSORS, "N23S0", "ControlStop", "1");
}
// Luz Persiana BAJA
if (L != null && L < UmbralOFF){
DriverHelper.ProcessCommad(Domains.MYSENSORS, "N23S0", "ControlUp", "1");

}
}

I always get error:
Error CS0019 in line 21 column 20, Operator `>' cannot be applied to operands of type `GenericDriver.ModuleParameter' and `int'
Error CS0019 in line 25 column 21, Operator `<=' cannot be applied to operands of type `GenericDriver.ModuleParameter' and `int'
Error CS0019 in line 29 column 21, Operator `<' cannot be applied to operands of type `GenericDriver.ModuleParameter' and `int'

Please Log in or Create an account to join the conversation.

9 years 6 months ago #1227 by EasyIoT
Replied by EasyIoT on topic Automation Light Level

osalval wrote: I'm trying to control Roller Shutter. The driver helper is easy to manage but read value of sensor not:

/*
This code is running one time when program is enabled
*/
int UmbralON = 520; // Umbral de desactivación
int UmbralOFF = 420; // Umbral de activación

public void Setup()
{
}

/*
This code is running periodicaly when program is enabled.
Cron job detirmine running period.
*/
public void Run()
{
ModuleParameter L = ModuleHelper.GetProperty(Domains.MYSENSORS, "N23S1", "Sensor.LightLevel");

// Luz Persiana ALTA
if (L != null && L > UmbralON) {
DriverHelper.ProcessCommad(Domains.MYSENSORS, "N23S0", "ControlDown", "1");
}
// Luz Persiana NORMAL
if (L != null && L <= UmbralON && L >= UmbralOFF){
DriverHelper.ProcessCommad(Domains.MYSENSORS, "N23S0", "ControlStop", "1");
}
// Luz Persiana BAJA
if (L != null && L < UmbralOFF){
DriverHelper.ProcessCommad(Domains.MYSENSORS, "N23S0", "ControlUp", "1");

}
}

I always get error:
Error CS0019 in line 21 column 20, Operator `>' cannot be applied to operands of type `GenericDriver.ModuleParameter' and `int'
Error CS0019 in line 25 column 21, Operator `<=' cannot be applied to operands of type `GenericDriver.ModuleParameter' and `int'
Error CS0019 in line 29 column 21, Operator `<' cannot be applied to operands of type `GenericDriver.ModuleParameter' and `int'


Module parameter is object and you can not compare object and int. Search forum and you will find solution.

Please Log in or Create an account to join the conversation.

9 years 6 months ago #1293 by osalval
Replied by osalval on topic Automation Light Level
New versión:
/*
Control Light Level
*/
int UmbralALTO = 520; // Umbral ALTO
int UmbralBAJO = 320; // Umbral BAJO

public void Setup()
{
EventHelper.ModuleChangedHandler((o, m, p) =>

{
ModuleParameter LL = ModuleHelper.GetProperty(Domains.MYSENSORS, "N23S1", "Sensor.LightLevel");

if (LL.DecimalValue > UmbralALTO){
Console.WriteLine(p.Value);
DriverHelper.ProcessCommad(Domains.MYSENSORS, "N23S0", "ControlDown", "");

}if (LL.DecimalValue <= UmbralALTO || LL.DecimalValue >= UmbralBAJO) {
Console.WriteLine(p.Value);
DriverHelper.ProcessCommad(Domains.MYSENSORS, "N23S0", "ControlStop", "");

}if (LL.DecimalValue < UmbralBAJO) {
Console.WriteLine(p.Value);
DriverHelper.ProcessCommad(Domains.MYSENSORS, "N23S0", "ControlUp", "");

}return true;

});
}

No errors but when enter in logic, the server gets crazy and enter in a infinity loop

How a simple Automation script (rule?) could be so complicated?

Please Log in or Create an account to join the conversation.

9 years 6 months ago #1295 by EasyIoT
Replied by EasyIoT on topic Automation Light Level

osalval wrote: New versión:
/*
Control Light Level
*/
int UmbralALTO = 520; // Umbral ALTO
int UmbralBAJO = 320; // Umbral BAJO

public void Setup()
{
EventHelper.ModuleChangedHandler((o, m, p) =>

{
ModuleParameter LL = ModuleHelper.GetProperty(Domains.MYSENSORS, "N23S1", "Sensor.LightLevel");

if (LL.DecimalValue > UmbralALTO){
Console.WriteLine(p.Value);
DriverHelper.ProcessCommad(Domains.MYSENSORS, "N23S0", "ControlDown", "");

}if (LL.DecimalValue <= UmbralALTO || LL.DecimalValue >= UmbralBAJO) {
Console.WriteLine(p.Value);
DriverHelper.ProcessCommad(Domains.MYSENSORS, "N23S0", "ControlStop", "");

}if (LL.DecimalValue < UmbralBAJO) {
Console.WriteLine(p.Value);
DriverHelper.ProcessCommad(Domains.MYSENSORS, "N23S0", "ControlUp", "");

}return true;

});
}

No errors but when enter in logic, the server gets crazy and enter in a infinity loop

How a simple Automation script (rule?) could be so complicated?


You shroud filter event only for one module. Add one if clause before GetProperty to filter module. Something like this:
if (m.domain == Domains.MYSENSORS  && m.address == "N23S1")
{
ModuleParameter LL = ModuleHelper.GetProperty(Domains.MYSENSORS, "N23S1", "Sensor.LightLevel");
.
.
.
.
}
The following user(s) said Thank You: osalval

Please Log in or Create an account to join the conversation.

9 years 6 months ago - 9 years 6 months ago #1296 by osalval
Replied by osalval on topic Automation Light Level
Hello, no luck.
I'm trying:
/*
Control Luz TV Despacho
*/
int UmbralALTO = 520; // Umbral ALTO
int UmbralBAJO = 420; // Umbral BAJO

public void Setup()
{
EventHelper.ModuleChangedHandler((o, m, p) =>

{
if (m.domain == Domains.MYSENSORS && m.address == "N23S1"){
ModuleParameter LL = ModuleHelper.GetProperty(Domains.MYSENSORS, "N23S1", "Sensor.LightLevel");
}
if (LL.DecimalValue > UmbralALTO){
Console.WriteLine(p.Value);
DriverHelper.ProcessCommad(Domains.MYSENSORS, "N23S0", "ControlDown", "1");

}if (LL.DecimalValue <= UmbralALTO || LL.DecimalValue >= UmbralBAJO) {
Console.WriteLine(p.Value);
DriverHelper.ProcessCommad(Domains.MYSENSORS, "N23S0", "ControlStop", "1");

}if (LL.DecimalValue < UmbralBAJO) {
Console.WriteLine(p.Value);
DriverHelper.ProcessCommad(Domains.MYSENSORS, "N23S0", "ControlUp", "1");

}return true;

});
}

Error CS1061 in line 12 column 13, Type `GenericDriver.Module' does not contain a definition for `domain' and no extension method `domain' of type `GenericDriver.Module' could be found. Are you missing an assembly reference?
Error in line -11 column 0, /home/pi/easyiot/GenericDriver.dll (Location of the symbol related to previous error)
Error CS0103 in line 15 column 7, The name `LL' does not exist in the current context
Error CS0103 in line 19 column 8, The name `LL' does not exist in the current context
Error CS0103 in line 23 column 8, The name `LL' does not exist in the current context

Line 12 is:
if (m.domain == Domains.MYSENSORS && m.address == "N23S1"){
I'm not understand why error states: Type `GenericDriver.Module' because should be MYSENSORS driver?

Please Log in or Create an account to join the conversation.

9 years 6 months ago #1297 by EasyIoT
Replied by EasyIoT on topic Automation Light Level

osalval wrote: Hello, no luck.
I'm trying:
/*
Control Luz TV Despacho
*/
int UmbralALTO = 520; // Umbral ALTO
int UmbralBAJO = 420; // Umbral BAJO

public void Setup()
{
EventHelper.ModuleChangedHandler((o, m, p) =>

{
if (m.domain == Domains.MYSENSORS && m.address == "N23S1"){
ModuleParameter LL = ModuleHelper.GetProperty(Domains.MYSENSORS, "N23S1", "Sensor.LightLevel");
}
if (LL.DecimalValue > UmbralALTO){
Console.WriteLine(p.Value);
DriverHelper.ProcessCommad(Domains.MYSENSORS, "N23S0", "ControlDown", "1");

}if (LL.DecimalValue <= UmbralALTO || LL.DecimalValue >= UmbralBAJO) {
Console.WriteLine(p.Value);
DriverHelper.ProcessCommad(Domains.MYSENSORS, "N23S0", "ControlStop", "1");

}if (LL.DecimalValue < UmbralBAJO) {
Console.WriteLine(p.Value);
DriverHelper.ProcessCommad(Domains.MYSENSORS, "N23S0", "ControlUp", "1");

}return true;

});
}

Error CS1061 in line 12 column 13, Type `GenericDriver.Module' does not contain a definition for `domain' and no extension method `domain' of type `GenericDriver.Module' could be found. Are you missing an assembly reference?
Error in line -11 column 0, /home/pi/easyiot/GenericDriver.dll (Location of the symbol related to previous error)
Error CS0103 in line 15 column 7, The name `LL' does not exist in the current context
Error CS0103 in line 19 column 8, The name `LL' does not exist in the current context
Error CS0103 in line 23 column 8, The name `LL' does not exist in the current context

Line 12 is:
if (m.domain == Domains.MYSENSORS && m.address == "N23S1"){
I'm not understand why error states: Type `GenericDriver.Module' because should be MYSENSORS driver?


My code was untested. Address and domain starts with capital letter:
if (m.Domain == Domains.MYSENSORS && m.Address == "N23S1"){

Please read tutorials and other code examples on this site.
The following user(s) said Thank You: osalval

Please Log in or Create an account to join the conversation.

Time to create page: 0.309 seconds

Forum latest

  • No posts to display.