Author Topic: Digging into Climate plugin:got out with some interesting features  (Read 8560 times)

bulek

  • Administrator
  • wants to work for LinuxMCE
  • *****
  • Posts: 909
  • Living with LMCE
    • View Profile
Hi,

since I'm trying to support quite some different devices in my home, I'd also like to interact with them properly through floorplans on Orbiters...

I currently spot some inconsintencies and also unifinished features in floorplan devices, so I'm starting my adventure into Climate and Lighting plugins (cause they suit my newbie knowledge of programming). Thread and wiki page for lighting plugin will follow... Now back to Climate Plugin.

I've started wiki page with highlights of code and behaviour and also my comments, my opinions what is probably not done ok (I could be easily missing something - I hope "senior developers" will correct me where necessary)...

http://wiki.linuxmce.org/index.php/Climate_Plugin

I'd be happy to see some discussion on this matter. I propose few quite enhancements (so less info is displayed for simple sensors and also display of devices in colors showing their state is better supported). I'm curious if they make sense....

I plan to try to make those enhancements, but would like to get some supervision from developers and also discussion about this matter, so we can clear out how the things regarding climate devices are supposed to be...

I also think that some discussion would be good on support for Blinds,Drapes and Shutter devices. I guess they belong to this category, but currently they don't seem to be supported at all. I guess displayed dimmed light controls is a solution for a start...

Thanks in advance,

regards,

Bulek.


« Last Edit: December 10, 2008, 12:33:26 pm by bulek »
Thanks in advance,

regards,

Bulek.

tschak909

  • LinuxMCE God
  • ****
  • Posts: 5549
  • DOES work for LinuxMCE.
    • View Profile
Re: Digging into Climate plugin
« Reply #1 on: December 02, 2008, 03:23:57 pm »
Thank you, Bulek :)

-Thom

hari

  • Administrator
  • LinuxMCE God
  • *****
  • Posts: 2428
    • View Profile
    • ago control
Re: Digging into Climate plugin
« Reply #2 on: December 02, 2008, 03:46:31 pm »
i'll look at the air quality stuff, like activate a fan or open a window when e.g. co2 levels are too high. I'm awaiting plenty of z-wave sensors for other measurements, too..

br, Hari
rock your home - http://www.agocontrol.com home automation

tschak909

  • LinuxMCE God
  • ****
  • Posts: 5549
  • DOES work for LinuxMCE.
    • View Profile
Re: Digging into Climate plugin
« Reply #3 on: December 02, 2008, 04:33:29 pm »
See, i await the day when we sense that i'm sitting down in the chair, and i'm sweating, and it turns on the fan....

:D

hari

  • Administrator
  • LinuxMCE God
  • *****
  • Posts: 2428
    • View Profile
    • ago control
Re: Digging into Climate plugin
« Reply #4 on: December 02, 2008, 06:05:24 pm »
it will even open the window when you fart..
rock your home - http://www.agocontrol.com home automation

bulek

  • Administrator
  • wants to work for LinuxMCE
  • *****
  • Posts: 909
  • Living with LMCE
    • View Profile
Re: Digging into Climate plugin
« Reply #5 on: December 02, 2008, 07:55:38 pm »
I also spot that Sprinkler devices don't work.

To check: put Standard Sprinkler device on floorplan and then click on controls on right column. For me, I can only see that Off command gets sent, clicking on others doesn't produce any DCE message.

Can anyone confirm that ?

I'd be happy to hear some discussion on this matter, so I can try to fix things...

Thanks in advance,

regards,

Bulek.
Thanks in advance,

regards,

Bulek.

bulek

  • Administrator
  • wants to work for LinuxMCE
  • *****
  • Posts: 909
  • Living with LMCE
    • View Profile
Re: Digging into Climate plugin
« Reply #6 on: December 09, 2008, 07:42:58 pm »
Hi,

I'd kindly ask more LMCE and c++ experienced guys to help me with determinining device template of device that is subject of highlighted Climate_Plugin::GetFloorplanDeviceInfo method. It seems like pointer to DeviceData_Router is the only option, but I don't know if I can get some more device data (most important is template) via that pointer...  How can I get to device data from this subroutine, or how can I do this in general ? Is there any other example that I should look and learn ?

Thanks in advance,

regards,

Bulek.


Code: [Select]
void Climate_Plugin::GetFloorplanDeviceInfo(DeviceData_Router *pDeviceData_Router,EntertainArea *pEntertainArea,int iFloorplanObjectType,int &iPK_FloorplanObjectType_Color,int &Color,string &sDescription,string &OSD,int &PK_DesignObj_Toolbar)
{
switch(iFloorplanObjectType)
{
case FLOORPLANOBJECTTYPE_CLIMATE_THERMOSTAT_CONST:
PK_DesignObj_Toolbar=DESIGNOBJ_grpThermostatControls_CONST;
break;
case FLOORPLANOBJECTTYPE_CLIMATE_THERMOMETER_CONST:
PK_DesignObj_Toolbar=0;
break;
case FLOORPLANOBJECTTYPE_CLIMATE_WEATHER_STATION_CONST:
PK_DesignObj_Toolbar=0;
break;
case FLOORPLANOBJECTTYPE_CLIMATE_DAMPER_CONST:
PK_DesignObj_Toolbar=0;
break;
case FLOORPLANOBJECTTYPE_CLIMATE_POOL_CONST:
PK_DesignObj_Toolbar=DESIGNOBJ_grpPoolControls_CONST;
break;
case FLOORPLANOBJECTTYPE_CLIMATE_SPRINKLER_CONST:
PK_DesignObj_Toolbar=DESIGNOBJ_grpSprinklerControls_CONST;
break;
};
if( (OSD=pDeviceData_Router->m_sState_get())=="OFF" )
iPK_FloorplanObjectType_Color = FLOORPLANOBJECTTYPE_COLOR_CLIMATE_THERMOSTAT_OFF_CONST;
else
iPK_FloorplanObjectType_Color = FLOORPLANOBJECTTYPE_COLOR_CLIMATE_THERMOSTAT_COOLING_CONST;
}
Thanks in advance,

regards,

Bulek.

bulek

  • Administrator
  • wants to work for LinuxMCE
  • *****
  • Posts: 909
  • Living with LMCE
    • View Profile
Re: Digging into Climate plugin:got out with some interesting features
« Reply #7 on: December 10, 2008, 12:42:38 pm »
Hi,

I digged in and came out alive :-) ....

I've come up with quite flexible idea of controlling what is displayed on floorplans for Climate devices (this could be easily extended to all rendering plugins)...

I've done this:
- by default behaviour stays the same as before
- if you add Extra parameters data to certain device, then you can control info displayed on floorplan by its content:

State for Climate devices consists of following parts :
OSD display format for Orbiter floorplan ($1=ON/OFF,$2=HEAT|COOL|FAN_ONLY|AUTO,$3=HIGH|AUTO,$4=SET TEMP ($5=CURRENT TEMP))

for instance: default string value for displaying exactly the same info as it is know is :
'$1/$2/$3/$4 ($5)'   - omit quotes!

Climate device has a state consisting of five components: Active($1), Mode($2), FanMode($3),Setpoint($4),ActualTemp($5) and by default everything is displayed on floorplan... Now by changing this string you can easily control/select and add text info to floorplan - few examples :
'Outside ($5)'     will display text Outside and then ActualTemp
'$2 ($4)'            this is probably the thing for actual thermostat without fan....

OSD string is changed from default - computed :
- only if Extra parameters string exists
- if they exist, $1..$5 are replaced by actual values one by one
- everything else is intact...

I've tried to do this on my 710 system and must admit that now my floorplan is getting more user friendly and informative....

What do you think about solution ?

I also have an idea for further possible replacement of hardcoded states that are displayed on floorplans:
- for instance what if you don't like HEAT/COOL/AUTO, then you could set an replacement for them -something like
'$1/$2/$3/$4 ($5) $3=HEAT|High;COOL|Low'   - omit quotes!

That means that when evaluating $3, state of 'HEAT' is replaced by custom 'High'... I think this is not so hard to code, but it's beyond my c++ knowledge, so if anyone can come up with a bit of help it would be welcome.... With this possibility you gain total control of what is displayed on floorplan and you can easily customize things on floorplan...

Thanks in advance,

regards,

Bulek.
« Last Edit: December 11, 2008, 09:56:25 am by bulek »
Thanks in advance,

regards,

Bulek.

tschak909

  • LinuxMCE God
  • ****
  • Posts: 5549
  • DOES work for LinuxMCE.
    • View Profile
Re: Digging into Climate plugin:got out with some interesting features
« Reply #8 on: December 10, 2008, 04:49:42 pm »
Thank you for this enhancement :) As I said earlier, I'm not in this part of the code at the moment, so I can't provide any good feedback, yet... but I would love to try it out soon.

-Thom

bulek

  • Administrator
  • wants to work for LinuxMCE
  • *****
  • Posts: 909
  • Living with LMCE
    • View Profile
Hi,

since my time is running out and there is not much chance to do this properly on 810 release, I'm posting patch file for Climate plugin made on 710 release.

I guess Climate plugin didn't change much, so I hope that one of the developers will succeed applying this patch in 810 release....

Basically this patch is harmless - the default behaviour stays the same, but user can activate additional floorplan display features by adding device data. Guide is here :

http://wiki.linuxmce.org/index.php/Climate_Plugin#Description_of_enhanced_710_plugin_and_ability_to_control_displayed_info_on_floorplans

I run out of time, wanted to do also possibility to replace certain keywords with custom one, but will probably do that later. Similar changes could be made to other similar floorplan plugins, but there are some other problems to solve - with Lighting plugin I think JonDecker promised a quick fix so device state will be displayed on floorplan at all - we can proceed from there....

I'd kindly ask if you can review it and if accepted, try to apply it.

Thanks in advance,

regards,

Bulek.


Code: [Select]
*** Climate_Plugin.cpp.orig 2008-12-02 14:54:09.000000000 +0100
--- Climate_Plugin.cpp 2008-12-10 22:41:44.000000000 +0100
***************
*** 167,176 ****
--- 167,192 ----
  //<-dceag-createinst-b->!
  void Climate_Plugin::GetFloorplanDeviceInfo(DeviceData_Router *pDeviceData_Router,EntertainArea *pEntertainArea,int iFloorplanObjectType,int &iPK_FloorplanObjectType_Color,int &Color,string &sDescription,string &OSD,int &PK_DesignObj_Toolbar)
  {
+ string sOn; string sMode; string sFan; string sSetPoint; string sTemp;
+ GetStateVar(pDeviceData_Router, sOn, sMode, sFan, sSetPoint, sTemp);
+
+ if( sOn.c_str()=="OFF" ) {
+ iPK_FloorplanObjectType_Color = FLOORPLANOBJECTTYPE_COLOR_CLIMATE_THERMOSTAT_OFF_CONST;
+ } else {
+ iPK_FloorplanObjectType_Color = FLOORPLANOBJECTTYPE_COLOR_CLIMATE_THERMOSTAT_COOLING_CONST;
+ };
+
  switch(iFloorplanObjectType)
  {
  case FLOORPLANOBJECTTYPE_CLIMATE_THERMOSTAT_CONST:
  PK_DesignObj_Toolbar=DESIGNOBJ_grpThermostatControls_CONST;
+ if ( sMode=="HEAT" ) {
+ iPK_FloorplanObjectType_Color = FLOORPLANOBJECTTYPE_COLOR_CLIMATE_THERMOSTAT_HEATING_CONST;
+ } else if ( sMode=="COOL" ) {
+ iPK_FloorplanObjectType_Color = FLOORPLANOBJECTTYPE_COLOR_CLIMATE_THERMOSTAT_COOLING_CONST;
+ } else if ( sMode=="AUTO" ) {
+ iPK_FloorplanObjectType_Color = FLOORPLANOBJECTTYPE_COLOR_CLIMATE_THERMOSTAT_FAN_CONST;
+ };
  break;
  case FLOORPLANOBJECTTYPE_CLIMATE_THERMOMETER_CONST:
  PK_DesignObj_Toolbar=0;
***************
*** 183,197 ****
  break;
  case FLOORPLANOBJECTTYPE_CLIMATE_POOL_CONST:
  PK_DesignObj_Toolbar=DESIGNOBJ_grpPoolControls_CONST;
  break;
  case FLOORPLANOBJECTTYPE_CLIMATE_SPRINKLER_CONST:
  PK_DesignObj_Toolbar=DESIGNOBJ_grpSprinklerControls_CONST;
  break;
  };
! if( (OSD=pDeviceData_Router->m_sState_get())=="OFF" )
! iPK_FloorplanObjectType_Color = FLOORPLANOBJECTTYPE_COLOR_CLIMATE_THERMOSTAT_OFF_CONST;
! else
! iPK_FloorplanObjectType_Color = FLOORPLANOBJECTTYPE_COLOR_CLIMATE_THERMOSTAT_COOLING_CONST;
  }
 
  bool Climate_Plugin::ClimateCommand( class Socket *pSocket, class Message *pMessage, class DeviceData_Base *pDeviceFrom, class DeviceData_Base *pDeviceTo )
--- 199,248 ----
  break;
  case FLOORPLANOBJECTTYPE_CLIMATE_POOL_CONST:
  PK_DesignObj_Toolbar=DESIGNOBJ_grpPoolControls_CONST;
+ if( sMode=="HEAT" ) {
+ iPK_FloorplanObjectType_Color = FLOORPLANOBJECTTYPE_COLOR_CLIMATE_THERMOSTAT_HEATING_CONST;
+ } else if ( sMode=="COOL" ) {
+ iPK_FloorplanObjectType_Color = FLOORPLANOBJECTTYPE_COLOR_CLIMATE_THERMOSTAT_COOLING_CONST;
+ } else if ( sMode=="AUTO" ) {
+ iPK_FloorplanObjectType_Color = FLOORPLANOBJECTTYPE_COLOR_CLIMATE_THERMOSTAT_FAN_CONST;
+ };
  break;
  case FLOORPLANOBJECTTYPE_CLIMATE_SPRINKLER_CONST:
  PK_DesignObj_Toolbar=DESIGNOBJ_grpSprinklerControls_CONST;
+ if( sOn=="ON" )
+ iPK_FloorplanObjectType_Color = FLOORPLANOBJECTTYPE_COLOR_CLIMATE_THERMOSTAT_HEATING_CONST;
+ else if ( sOn=="OFF" )
+ iPK_FloorplanObjectType_Color = FLOORPLANOBJECTTYPE_COLOR_CLIMATE_THERMOSTAT_FAN_CONST;
  break;
+ default:
+ PK_DesignObj_Toolbar=0;
+ break;
+ };       
+
+ string sExtra_Parameters = pDeviceData_Router->m_mapParameters_Find(DEVICEDATA_Extra_Parameters_CONST);
+
+ if (sExtra_Parameters.length() > 0) {
+ string Test = "Extra parameters present!";
+ // LoggerWrapper::GetInstance()->Write(LV_CRITICAL,"Climate_Plugin::GetFloorplanDeviceInfo |Got current state info %s %s %s %s %s",sOn.c_str(),sMode.c_str(), sFan.c_str(),sSetPoint.c_str(),sTemp.c_str());
+
+ string sTemp_OSD_String = sExtra_Parameters.c_str();
+ unsigned int pos;
+ if ((pos=sTemp_OSD_String.find("$1",0)) != string::npos) sTemp_OSD_String.replace( pos, 2, sOn);
+ if ((pos=sTemp_OSD_String.find("$2",0)) != string::npos) sTemp_OSD_String.replace( pos, 2, sMode);
+ if ((pos=sTemp_OSD_String.find("$3",0)) != string::npos) sTemp_OSD_String.replace( pos, 2, sFan);
+ if ((pos=sTemp_OSD_String.find("$4",0)) != string::npos) sTemp_OSD_String.replace( pos, 2, sSetPoint);
+ if ((pos=sTemp_OSD_String.find("$5",0)) != string::npos) sTemp_OSD_String.replace( pos, 2, sTemp);
+ OSD=sTemp_OSD_String.c_str();
+ // LoggerWrapper::GetInstance()->Write(LV_CRITICAL,"Climate_Plugin::GetFloorplanDeviceInfo |Extra parameters found: %s | NEW OSD is %s",sExtra_Parameters.c_str(),sTemp_OSD_String.c_str());
+
+ } else {
+ OSD=pDeviceData_Router->m_sState_get();
+ // LoggerWrapper::GetInstance()->Write(LV_CRITICAL,"Climate_Plugin::GetFloorplanDeviceInfo |Extra parameters not found!");
  };
!
!
! // LoggerWrapper::GetInstance()->Write(LV_CRITICAL,"Climate_Plugin::GetFloorplanDeviceInfo |  Device ID:%d Install_ID:%d Template:%d Category:%d Room:%d",pDeviceData_Router->m_dwPK_Device,pDeviceData_Router->m_dwPK_Installation,pDeviceData_Router->m_dwPK_DeviceTemplate,pDeviceData_Router->m_dwPK_DeviceCategory,pDeviceData_Router->m_dwPK_Room);
!
  }
 
  bool Climate_Plugin::ClimateCommand( class Socket *pSocket, class Message *pMessage, class DeviceData_Base *pDeviceFrom, class DeviceData_Base *pDeviceTo )
***************
*** 230,237 ****
  string sSetPoint;
  string sTemp;
  GetStateVar(pDevice, sOn, sMode, sFan, sSetPoint, sTemp);
!
! // The State is in the format ON|OFF/SET TEMP (CURRENT TEMP)
  if( pMessage->m_dwMessage_Type==MESSAGETYPE_COMMAND )
  {
  if( pMessage->m_dwID==COMMAND_Set_Level_CONST )
--- 281,288 ----
  string sSetPoint;
  string sTemp;
  GetStateVar(pDevice, sOn, sMode, sFan, sSetPoint, sTemp);
!
! // The State is in the format ON|OFF/HEAT|COOL|FAN_ONLY|AUTO/HIGH|AUTO/SET TEMP (CURRENT TEMP)
  if( pMessage->m_dwMessage_Type==MESSAGETYPE_COMMAND )
  {
  if( pMessage->m_dwID==COMMAND_Set_Level_CONST )
***************
*** 251,257 ****
  pMessage->m_dwID=COMMAND_Generic_Off_CONST;
  else
  {
! pDevice->m_sState_set("ON/" + StringUtils::itos(iLevel) + GetTemperature(pDevice));
  pMessage->m_mapParameters[COMMANDPARAMETER_Level_CONST] = StringUtils::itos(iLevel);
  }
  }
--- 302,310 ----
  pMessage->m_dwID=COMMAND_Generic_Off_CONST;
  else
  {
! // pDevice->m_sState_set("ON/" + StringUtils::itos(iLevel) + GetTemperature(pDevice)); /Replaced with clause below
! SetStateValue(pDevice, "ON", sMode, sFan, StringUtils::itos(iLevel), sTemp);
!
  pMessage->m_mapParameters[COMMANDPARAMETER_Level_CONST] = StringUtils::itos(iLevel);
  }
  }

Thanks in advance,

regards,

Bulek.

Marie.O

  • Administrator
  • LinuxMCE God
  • *****
  • Posts: 3676
  • Wastes Life On LinuxMCE Since 2007
    • View Profile
    • My Home
Re: Digging into Climate plugin:got out with some interesting features
« Reply #10 on: March 03, 2009, 10:22:00 pm »
Bulek,

please post the patch as a feature patch on trac http://svn.linuxmce.org/

hari

  • Administrator
  • LinuxMCE God
  • *****
  • Posts: 2428
    • View Profile
    • ago control
Re: Digging into Climate plugin:got out with some interesting features
« Reply #11 on: March 04, 2009, 07:11:24 pm »
Committed revision 21751.

rock your home - http://www.agocontrol.com home automation

jondecker76

  • Alumni
  • wants to work for LinuxMCE
  • *
  • Posts: 763
    • View Profile
Re: Digging into Climate plugin:got out with some interesting features
« Reply #12 on: March 05, 2009, 12:55:02 am »
Bulek - I will work on getting the OSD text back on the floorplan this weekend and channeled into 0810.

Also, I want to see if an old bug is fixed where it wouldn't let you put the OSD text below the icon in the past (this would be the most space efficient way to display the text).

bulek

  • Administrator
  • wants to work for LinuxMCE
  • *****
  • Posts: 909
  • Living with LMCE
    • View Profile
Re: Digging into Climate plugin:got out with some interesting features
« Reply #13 on: March 05, 2009, 02:12:46 am »
Bulek - I will work on getting the OSD text back on the floorplan this weekend and channeled into 0810.

Also, I want to see if an old bug is fixed where it wouldn't let you put the OSD text below the icon in the past (this would be the most space efficient way to display the text).
ok,

thanks....

regards,

Bulek.
Thanks in advance,

regards,

Bulek.

jondecker76

  • Alumni
  • wants to work for LinuxMCE
  • *
  • Posts: 763
    • View Profile
Re: Digging into Climate plugin:got out with some interesting features
« Reply #14 on: March 11, 2009, 02:10:20 am »
I finally got the OSD back onto the floorplan (0810 only), but the old bug I mentioned still exists.... You can see the following for the 2 trac tickets I created about it. Its the same problem where text x and y isn't offset as it should, causing text to overlap the icon and become unreadable while the light is off.
http://svn.linuxmce.org/trac.cgi/ticket/134
http://svn.linuxmce.org/trac.cgi/ticket/133

Anyways, if you are using 0810, you can at least start adding your enhancements to Lighting_Plugin now.

Jon