Skip to content

Commit d4e0292

Browse files
committed
fix for external temp sensors
1 parent fbf3d6f commit d4e0292

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

ContromeToOpenHAB/ContromeToOpenHAB.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<StartupObject>ContromeToOpenHAB.Program</StartupObject>
99
<AssemblyVersion>1.4.0.0</AssemblyVersion>
1010
<FileVersion>1.4.0.0</FileVersion>
11-
<Version>1.4.0-beta</Version>
11+
<Version>1.4.0-beta3</Version>
1212
</PropertyGroup>
1313

1414
<ItemGroup>

ContromeToOpenHAB/Program.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using ContromeToOpenHAB.JSON;
33
using Newtonsoft.Json.Linq;
44
using RestSharp;
5+
using RestSharp.Authenticators;
56
using System;
67
using System.Collections.Generic;
78
using System.Diagnostics;
@@ -191,7 +192,11 @@ static void Run(Options options)
191192
strJpath = $"$..raeume[?(@.id=={strRoomID})]..sensoren[?(@.name=='{sensorId}')].wert";
192193

193194
thingsFile.Write($"\t\tType number : {strEscapedName}_{strSensorName} \"{strSensorDescription}\" [stateExtension=\"{strGetTemps}\", stateTransformation=\"JSONPATH:{strJpath}\"");
194-
if (blnIsExternalTemp || blnIsExternalHumidity)
195+
if (blnIsExternalTemp)
196+
{
197+
thingsFile.Write($", commandExtension=\"set/{sensorId}/temperatur/%2$\", commandTransformation=\"JS:ContromeValue.js\" ");
198+
}
199+
else if(blnIsExternalHumidity)
195200
{
196201
thingsFile.Write($", commandExtension=\"set/{sensorId}/%2$.2f\" ");
197202
}
@@ -256,6 +261,7 @@ static void Run(Options options)
256261
thingsFile.WriteLine("}");
257262
}
258263
}
264+
CreateJSValueTransform(options);
259265
DirectoryInfo confDir = new DirectoryInfo(Path.Combine(options.OutputDir, "conf"));
260266
Console.WriteLine("Created config files at " + confDir.FullName);
261267
}
@@ -311,7 +317,19 @@ private static IEnumerable<char> Escape(string strRoomName)
311317
else
312318
yield return '_';
313319
}
314-
320+
private static void CreateJSValueTransform(Options options)
321+
{
322+
using(var file =CreateConfigFile(options,Path.Combine("transform","ContromeValue.js")))
323+
{
324+
file.Write(@"(function(T) {
325+
//https://community.openhab.org/t/controme-smart-heat/26797/22
326+
var temp_coarse= Math.floor(T*2)/2; // T is true measured float temperature value
327+
var temp_fine= T-temp_coarse;
328+
var value = temp_coarse+ Math.floor(2.0*temp_fine + Math.floor(temp_fine*16) *6.25)/100;
329+
return value.toFixed(2);
330+
})(value)");
331+
}
332+
}
315333
private static StreamWriter CreateConfigFile(Options options, string strName)
316334
{
317335
string strPath = Path.Combine(options.OutputDir, Path.Combine("conf", strName));

0 commit comments

Comments
 (0)