simont77 / fakegato-history

Module to emulate Elgato Eve history
MIT License
166 stars 17 forks source link

Eve show negative values for temperature (internet speed) in history #85

Open Kienz opened 4 years ago

Kienz commented 4 years ago

I want to log the internet speeds in fakegato-history in Mbps. In the fakegato-history json file the values look good. Plugin: https://github.com/Kienz/homebridge-speedtest-net

persistent json: {"firstEntry":0,"lastEntry":2,"usedMemory":2,"refTime":608625820.9330001,"initialTime":1586933020.933,"history":["noValue",{"time":1586933020.933,"setRefTime":1},{"time":1586933020.933,"temp":422.75,"humidity":17.97,"pressure":55}]}

temp = download speed humidity = upload speed pressure = ping in ms

homebridge log: 4/15/2020, 8:43:40 AM] [Internet] Download: 422.75 Mbps [4/15/2020, 8:43:40 AM] [Internet] Upload: 17.97 Mbps [4/15/2020, 8:43:40 AM] [Internet] Ping: 55 ms [4/15/2020, 8:43:40 AM] [Internet] External IP: 149.172.218.226 [4/15/2020, 8:43:40 AM] [Internet] Add history data 422.75 17.97 55 [4/15/2020, 8:43:40 AM] [Internet] First entry Internet: 0 [4/15/2020, 8:43:40 AM] [Internet] Last entry Internet: 2 [4/15/2020, 8:43:40 AM] [Internet] Used memory Internet: 2 [4/15/2020, 8:43:40 AM] [Internet] 116 Internet: 00000000000000009ce4462403 0102 0202 03020300c00f00000000000000000101 [4/15/2020, 8:43:40 AM] [Internet] ** Fakegato-storage write FS file: /homebridge/accessories/homebridge-4_Internet_persist.json "firstEntry":0,"lastEntry":2,"usedMemory":2,"refTime":608625820.9330001,"initial [4/15/2020, 8:44:28 AM] [Internet] Data request Internet: 01140100000000 [4/15/2020, 8:44:28 AM] [Internet] Address requested Internet: 1 [4/15/2020, 8:44:28 AM] [Internet] Internet Entry: 2, Address: 2 [4/15/2020, 8:44:28 AM] [Internet] Data Internet: 1501000000 0100 0000 819ce446240000 0000 00 0000 10 02000000000000000723a505072602

Eve shows for this entry the value "-232,6" (in celcius). What is wrong? I'm using the temperature service and the "weather" fakegato-history.

simont77 commented 4 years ago

CurrentTemperature is by default limited to 0-100°C in Homekit. Maybe this is the reason of the strange behavior. You could try to change the MaxValue property of the Temperature characteristics in your Accessory. It is also possible that Eve simply misunderstand values outside the usual range.

tobekas commented 4 years ago

The entry for temperature in Eve‘s history protocol is 2 byte with 2 decimals, so it technically can hold values in the range of -327,68...327,67. Your value is too high, so there will be an overflow. This might be different for the actual temperature value (default Homekit value), since this data type is FLOAT als min/max value properties can be adjusted. But for history values you have this restriction.

ebaauw commented 4 years ago

I wouldn't try and go below -273.15, though.

Kienz commented 4 years ago

I got values from +381.7 to -385.7 🧐

jhubig commented 3 years ago

Hello,

I have changed the characteristic of CurrentTemperature in \usr\local\lib\node_modules\homebridge\node_modules\hap-nodejs\dist\lib\gen\HomeKit.js file.

image

Now I can see negative values displayed in HomeKit (e.g. in iOS Eve App). But in the fakegato history file I can still see null for the temperature values which leads to measurement entries in Eve App shown with 0.0. Something else I need to change? Thanks for your help.

{"temp":null,"humidity":93.9,"ppm":0,"time":1605996070}

image

NorthernMan54 commented 3 years ago

What does your addentry look like? The null value suggests that temperature is not being passed.

jhubig commented 3 years ago

I'm using the homebridge-cmd4 plugin which adds the data to fakegato history. Here the part where the values are added:

firstParm       = this.fakegatoConfig['temp']       || '0';
               secondParm      = this.fakegatoConfig['humidity']   || '0';
               thirdParm       = this.fakegatoConfig['ppm']        || '0';
               ucFirstParm     = ucFirst(firstParm)       || '0';
               ucSecondParm    = ucFirst(secondParm)      || '0';
               ucThirdParm     = ucFirst(thirdParm)       || '0';

               firstParmIndex = CMD4_ACC_TYPE_ENUM.properties.indexOfEnum(i => i.type === ucFirstParm);
               secondParmIndex = CMD4_ACC_TYPE_ENUM.properties.indexOfEnum(i => i.type === ucSecondParm);
               thirdParmIndex = CMD4_ACC_TYPE_ENUM.properties.indexOfEnum(i => i.type === ucThirdParm);

               firstParmValue = (this.testStoredValueForIndex(firstParmIndex) < 0) ?
                  firstParmValue : this.getStoredValueForIndex(firstParmIndex);
               secondParmValue = (this.testStoredValueForIndex(secondParmIndex) < 0) ?
                  secondParmValue : this.getStoredValueForIndex(secondParmIndex);
               thirdParmValue = (this.testStoredValueForIndex(thirdParmIndex) < 0) ?
                  thirdParmValue : this.getStoredValueForIndex(thirdParmIndex);

               this.log.debug("Logging temp:%s humidity:%s ppm:%s", firstParmValue, secondParmValue, thirdParmValue);
               // Eve Room (TempSensor, HumiditySensor and AirQuality Services)
               this.loggingService.addEntry({time: moment().unix(),
                  temp:firstParmValue,
                  humidity:secondParmValue,
                  ppm:thirdParmValue});
               break;
            }

But logging is generally working. Just not the negative values. We have to be fast. I don't know how long we have these weather conditions 😃

image

simont77 commented 3 years ago

You should not tweak hap, to change the minimum temp use something like this in your plugin

this.YourService.getCharacteristic(Characteristic.CurrentTemperature).props.minValue = -50;

I add no issue in this way

jhubig commented 3 years ago

You should not tweak hap, to change the minimum temp use something like this in your plugin

OK. Understood.

I have also adapted it in the plugin (homebridge-cmd4\lib\CMD4_ACC_TYPE_ENUM.js). Something I missed?

38:  { type: "CurrentTemperature",
                characteristic: Characteristic.CurrentTemperature,
                props: {format: Characteristic.Formats.FLOAT,
                        unit: Characteristic.Units.CELSIUS,
                        maxValue: 100,
                        minValue: -100,
                        minStep: 0.1,
                        perms: [Characteristic.Perms.READ,
                                Characteristic.Perms.NOTIFY
                               ]
                       },
                validValues: {}
              },
simont77 commented 3 years ago

As NorthernMan54 said, it seems that the negative values are not passed at all to fakegato. Do you have any means to debug step-by-step?

NorthernMan54 commented 3 years ago

Just put your sensor in the freezer!

F4F24FC3-1D22-4944-9234-57D95BA2B70A

jhubig commented 3 years ago

As NorthernMan54 said, it seems that the negative values are not passed at all to fakegato. Do you have any means to debug step-by-step?

I'm currently trying it. Asked also the developer of the homebridge-cmd4 plugin for support. I'll keep you updated. Thanks for your help up to now.

@NorthernMan54: I tried to put the air conditioning system in the freezer. Unfortunately it was too big. 😀

jhubig commented 3 years ago

As NorthernMan54 said, it seems that the negative values are not passed at all to fakegato. Do you have any means to debug step-by-step?

I'm currently trying it. Asked also the developer of the homebridge-cmd4 plugin for support. I'll keep you updated. Thanks for your help up to now.

@NorthernMan54: I tried to put the air conditioning system in the freezer. Unfortunately it was too big. 😀

Another stupid question (sorry for that). But how can I find the debug messages from fakegato in the homebridge log. Checked for the fakegato keyword but couldn't find something. Thanks.

image

This is my /etc/default/homebridge:

# Defaults / Configuration options for homebridge
# The following settings tells homebridge where to find the config.json file and where to persist the data (i.e. pairing and others)
HOMEBRIDGE_OPTS=-U /var/homebridge -I

# If you uncomment the following line, homebridge will log more
# You can display this via systemd's journalctl: journalctl -f -u homebridge
# DEBUG=*
DEBUG=* homebridge -D
NorthernMan54 commented 3 years ago

Fakegato uses the -D option for debug logging and not DEBUG=*

jhubig commented 3 years ago

FYI: So as you mentioned already before, it might be the case that the plugin is already sending undefined to fakegato. I will check the plugin-code:

[11/29/2020, 5:50:26 PM] [Cmd4] getValue CurrentTemperature function for:Aussenluft returned:-0.9
[11/29/2020, 5:50:26 PM] [Cmd4] Logging temp:undefined humidity:85 ppm:0
[11/29/2020, 5:50:26 PM] [Cmd4] **Fakegato-timer: addData  Aussenluft { time: 1606668626, temp: undefined, humidity: 85, ppm: 0 }  immediate:  false