|
2 | 2 | using ContromeToOpenHAB.JSON; |
3 | 3 | using Newtonsoft.Json.Linq; |
4 | 4 | using RestSharp; |
| 5 | +using RestSharp.Authenticators; |
5 | 6 | using System; |
6 | 7 | using System.Collections.Generic; |
7 | 8 | using System.Diagnostics; |
@@ -191,7 +192,11 @@ static void Run(Options options) |
191 | 192 | strJpath = $"$..raeume[?(@.id=={strRoomID})]..sensoren[?(@.name=='{sensorId}')].wert"; |
192 | 193 |
|
193 | 194 | 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) |
195 | 200 | { |
196 | 201 | thingsFile.Write($", commandExtension=\"set/{sensorId}/%2$.2f\" "); |
197 | 202 | } |
@@ -256,6 +261,7 @@ static void Run(Options options) |
256 | 261 | thingsFile.WriteLine("}"); |
257 | 262 | } |
258 | 263 | } |
| 264 | + CreateJSValueTransform(options); |
259 | 265 | DirectoryInfo confDir = new DirectoryInfo(Path.Combine(options.OutputDir, "conf")); |
260 | 266 | Console.WriteLine("Created config files at " + confDir.FullName); |
261 | 267 | } |
@@ -311,7 +317,19 @@ private static IEnumerable<char> Escape(string strRoomName) |
311 | 317 | else |
312 | 318 | yield return '_'; |
313 | 319 | } |
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 | + } |
315 | 333 | private static StreamWriter CreateConfigFile(Options options, string strName) |
316 | 334 | { |
317 | 335 | string strPath = Path.Combine(options.OutputDir, Path.Combine("conf", strName)); |
|
0 commit comments