Dynamically enable an automation program

8 years 11 months ago #1253 by bri
Hi,

Excellent project and excellent support, through your tutorials and following support given to others I have built an IoT thermostat using only the ESP... great stuff, thanks!

I'm currently looking for a solution to have an automation program enabled dynamically. I have a script that will control my relay node on/off depending on what temperature is being sensed which works great but I would like to only enable that function as and when required. Also I would like to pass a variable (temperature set point) to that automation script.

Do you have any ideas?

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

8 years 11 months ago #1254 by bri
Ok, I was looking at it the wrong way :silly: , I've found a solution.

I've added another virtual analogue output module for setting the temperature and trigger the heating control via an event handler.

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

8 years 11 months ago #1259 by EasyIoT

bri wrote: Ok, I was looking at it the wrong way :silly: , I've found a solution.

I've added another virtual analogue output module for setting the temperature and trigger the heating control via an event handler.

Yes, use temperature (AO) virtual node to set temperature and digital output (DO) to switch on and on procedure.

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

8 years 11 months ago #1262 by bri
I'm having an issue tying a handler to the temperature (AO)

Here's what I have:
public void Setup() {
  EventHelper.ModuleChangedHandler((o, m, p) =>
    {
      if (m.Domain == Domains.VIRTUAL && m.Address == "N4S0" && p.Property == "Sensor.Temperature") {
        ModuleParameter temp = ModuleHelper.GetProperty(Domains.VIRTUAL, "N10S0", "Sensor.Temperature");
        ModuleParameter settemp = ModuleHelper.GetProperty(Domains.VIRTUAL, "N4S0", "Sensor.Temperature");

        if (temp!= null && temp.DecimalValue<settemp.DecimalValue) {
          DriverHelper.ProcessCommad(Domains.VIRTUAL, "N9S0", "ControlOn", "");}
        else {
          DriverHelper.ProcessCommad(Domains.VIRTUAL, "N9S0", "ControlOff", "");} 

        return true;
      }
    });
}

This returns an error: Error CS1643 in line 2 column 36, Not all code paths return a value in lambda expression of type 'System.Func'

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

8 years 11 months ago #1280 by EasyIoT

bri wrote: I'm having an issue tying a handler to the temperature (AO)

Here's what I have:

public void Setup() {
  EventHelper.ModuleChangedHandler((o, m, p) =>
    {
      if (m.Domain == Domains.VIRTUAL && m.Address == "N4S0" && p.Property == "Sensor.Temperature") {
        ModuleParameter temp = ModuleHelper.GetProperty(Domains.VIRTUAL, "N10S0", "Sensor.Temperature");
        ModuleParameter settemp = ModuleHelper.GetProperty(Domains.VIRTUAL, "N4S0", "Sensor.Temperature");

        if (temp!= null && temp.DecimalValue<settemp.DecimalValue) {
          DriverHelper.ProcessCommad(Domains.VIRTUAL, "N9S0", "ControlOn", "");}
        else {
          DriverHelper.ProcessCommad(Domains.VIRTUAL, "N9S0", "ControlOff", "");} 

        return true;
      }
    });
}

This returns an error: Error CS1643 in line 2 column 36, Not all code paths return a value in lambda expression of type 'System.Func'


You are missing one return statement.
The following user(s) said Thank You: bri

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

Time to create page: 0.269 seconds

Forum latest

  • No posts to display.