Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[persistence] previousState(true) returns current value when there is an unit applied on channel #3096

Closed
travnick opened this issue Sep 29, 2022 · 9 comments · Fixed by #3143
Assignees
Labels
bug An unexpected problem or unintended behavior of the Core

Comments

@travnick
Copy link

I've changed persistence engine from RRD4j to JDBC (mariadb) sice I've read somewhere that previousState is not working with RRD4j.

Unfortunately, previousState(true) does not work correctly for channels with unit of measurement set.

function PrintCurrentAndLastUpdate(thingName)
{
  var item = itemRegistry.getItem(thingName);
  
  logger.info(thingName + " previous state:\t" + persistence.previousState(item, true));
  logger.info(thingName + " last update:\t" + persistence.lastUpdate(item));
  logger.info(thingName + " current state:\t" + item.getState());
}

PrintCurrentAndLastUpdate("Rtl433_consumed_water");
PrintCurrentAndLastUpdate("Rtl433_time");
PrintCurrentAndLastUpdate("Rtl433_rssi");
2022-09-29 12:47:14.495 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Rtl433_time' changed from 2022-09-29T12:46:44.000+0200 to 2022-09-29T12:47:14.000+0200
2022-09-29 12:47:14.496 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Rtl433_rssi' changed from -0.112511 dBm to -0.213509 dBm

==> /var/log/openhab/openhab.log <==
2022-09-29 12:47:14.521 [INFO ] [org.openhab.rule.water_volume_change] - Rtl433_time previous state:    JdbcItem [name=Rtl433_time, state=2022-09-29T12:46:44.000+0200, timestamp=2022-09-29T12:46:44.457+02:00[Europe/Warsaw]]
2022-09-29 12:47:14.522 [INFO ] [org.openhab.rule.water_volume_change] - Rtl433_time last update:       2022-09-29T12:47:14.492+02:00[Europe/Warsaw]
2022-09-29 12:47:14.522 [INFO ] [org.openhab.rule.water_volume_change] - Rtl433_time current state:     2022-09-29T12:47:14.000+0200
2022-09-29 12:47:14.524 [INFO ] [org.openhab.rule.water_volume_change] - Rtl433_rssi previous state:    JdbcItem [name=Rtl433_rssi, state=-0.213509, timestamp=2022-09-29T12:47:14.496+02:00[Europe/Warsaw]]
2022-09-29 12:47:14.525 [INFO ] [org.openhab.rule.water_volume_change] - Rtl433_rssi last update:       2022-09-29T12:47:14.496+02:00[Europe/Warsaw]
2022-09-29 12:47:14.525 [INFO ] [org.openhab.rule.water_volume_change] - Rtl433_rssi current state:     -0.213509 dBm

without unit set (see rssi):

2022-09-29 12:47:50.420 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Rtl433_time' changed from 2022-09-29T12:47:14.000+0200 to 2022-09-29T12:47:50.000+0200
2022-09-29 12:47:50.420 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Rtl433_rssi' changed from -0.213509 to -0.125042

==> /var/log/openhab/openhab.log <==
2022-09-29 12:47:50.445 [INFO ] [org.openhab.rule.water_volume_change] - Rtl433_time previous state:    JdbcItem [name=Rtl433_time, state=2022-09-29T12:47:14.000+0200, timestamp=2022-09-29T12:47:14.492+02:00[Europe/Warsaw]]
2022-09-29 12:47:50.446 [INFO ] [org.openhab.rule.water_volume_change] - Rtl433_time last update:       2022-09-29T12:47:50.424+02:00[Europe/Warsaw]
2022-09-29 12:47:50.446 [INFO ] [org.openhab.rule.water_volume_change] - Rtl433_time current state:     2022-09-29T12:47:50.000+0200
2022-09-29 12:47:50.447 [INFO ] [org.openhab.rule.water_volume_change] - Rtl433_rssi previous state:    JdbcItem [name=Rtl433_rssi, state=-0.213509, timestamp=2022-09-29T12:47:18.177+02:00[Europe/Warsaw]]
2022-09-29 12:47:50.447 [INFO ] [org.openhab.rule.water_volume_change] - Rtl433_rssi last update:       2022-09-29T12:47:50.421+02:00[Europe/Warsaw]
2022-09-29 12:47:50.447 [INFO ] [org.openhab.rule.water_volume_change] - Rtl433_rssi current state:     -0.125042

Using openHAB 3.3.0

@J-N-K J-N-K added the bug An unexpected problem or unintended behavior of the Core label Sep 29, 2022
@J-N-K J-N-K self-assigned this Sep 29, 2022
@J-N-K
Copy link
Member

J-N-K commented Sep 29, 2022

Can you show the item definition? It seems that JDBC checks the item and adds a unit but your historic value has no unit.

@travnick
Copy link
Author

I have my mqtt channels handled with this:

UID: mqtt:topic:7e6ae66bff:988ecf11b0
label: Rtl 433
thingTypeUID: mqtt:topic
configuration: {}
bridgeUID: mqtt:broker:7e6ae66bff
channels:
  - id: water_timestamp
    channelTypeUID: mqtt:datetime
    label: time
    description: null
    configuration:
      stateTopic: sensor/rtl_433/1946185/time
  - id: water_rssi
    channelTypeUID: mqtt:number
    label: rssi
    description: null
    configuration:
      unit: dBm
      min: -30
      stateTopic: sensor/rtl_433/1946185/rssi
      max: 0
  - id: water_use_total
    channelTypeUID: mqtt:number
    label: total use
    description: null
    configuration:
      unit: m³
      min: 0
      stateTopic: sensor/rtl_433/1946185/data
      transformationPattern: EXEC:/usr/local/bin/exec_wmbusmeters %s∩JSONPATH:$.total_m3
      max: 1000
  - id: water_use_delta
    channelTypeUID: mqtt:number
    label: delta use
    description: null
    configuration:
      unit: dm³
      min: 0
      stateTopic: sensor/rtl_433/1946185/water_use_delta
      max: 1000
  - id: rtl433_raw_event
    channelTypeUID: mqtt:string
    label: Rtl433 raw event
    description: ""
    configuration:
      stateTopic: sensor/rtl_433/events

@J-N-K
Copy link
Member

J-N-K commented Sep 30, 2022

Persistence knows nothing about things or channels, only about items and states. If there is an issue, it's with the item, so I need the item definition.

@travnick
Copy link
Author

travnick commented Oct 5, 2022

Where can I find this? Would you like to see the screenshots? I'm using UI, I do not see any .item file (as found in documentation) in a filesystem

openhab-cli info

Version:     3.3.0 (Build)

User:        openhab (Active Process 22307)
User Groups: openhab tty dialout audio wmbusmeters

Directories: Folder Name      | Path                        | User:Group
             -----------      | ----                        | ----------
             OPENHAB_HOME     | /usr/share/openhab          | openhab:openhab
             OPENHAB_RUNTIME  | /usr/share/openhab/runtime  | openhab:openhab
             OPENHAB_USERDATA | /var/lib/openhab            | openhab:openhab
             OPENHAB_CONF     | /etc/openhab                | openhab:openhab
             OPENHAB_LOGDIR   | /var/log/openhab            | openhab:openhab

@J-N-K
Copy link
Member

J-N-K commented Oct 5, 2022

Bildschirmfoto 2022-10-05 um 18 29 43

Something like this would help.

@travnick
Copy link
Author

travnick commented Oct 6, 2022

image

@J-N-K
Copy link
Member

J-N-K commented Oct 15, 2022

Which openHAB version is this? I can't find anything that could go wrong there.

@travnick
Copy link
Author

as mentioned openhab 3.3.0-1, running on Debian from https://openhab.jfrog.io/artifactory/openhab-linuxpkg stable main

# lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description:    Debian GNU/Linux 10 (buster)
Release:        10
Codename:       buster

@J-N-K
Copy link
Member

J-N-K commented Nov 5, 2022

Can you try adding state description Metadata (like %.4f dBm) and see if that helps? This probably the same as #3121, because if no state description is set and no default unit is provided (i.e. the UnitProvider has doesn't know about that dimension, which is the case for "Power"), the states are restored without unit and comparison fails to determine the correct state. It works for me for "Pressure" and "Temperature".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An unexpected problem or unintended behavior of the Core
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants