domogik / domoweb

Web interface for Domogik Home Automation free software
24 stars 10 forks source link

Widget does not display the value calculated by the formula #53

Closed vdomos closed 7 years ago

vdomos commented 9 years ago

Hello,

I configured a device with a formula for testing in admin GUI, like this.

domogik_device_formula

The calculated values are stored in database:

[
    {
        "date": "2015-11-02T23:27:02",
        "id": 81366,
        "original_value_num": 2.6,
        "sensor_id": 105,
        "value_num": 260.0,
        "value_str": "260.0"
    }
]

But widget in Domoweb still display original value:

domoweb_widget_luminosity

cereal2nd commented 9 years ago

This is not a domoweb bug, the formula should be applied before its stored in the db

On Mon, Nov 2, 2015 at 11:30 PM, vdomos notifications@github.com wrote:

Hello,

I configured a device with a formula for testing in admin GUI, like this.

[image: domogik_device_formula] https://cloud.githubusercontent.com/assets/1257481/10896146/6b7fb25a-81b8-11e5-88cc-f9617d058050.png

The calculated values are stored in database:

[ { "date": "2015-11-02T23:27:02", "id": 81366, "original_value_num": 2.6, "sensor_id": 105, "value_num": 260.0, "value_str": "260.0" } ]

But widget in Domoweb still display original value:

[image: domoweb_widget_luminosity] https://cloud.githubusercontent.com/assets/1257481/10896252/0438e50c-81b9-11e5-94e9-cf2b6c071cdd.png

— Reply to this email directly or view it on GitHub https://github.com/domogik/domoweb/issues/53.

vdomos commented 9 years ago

In this case, I do not understand the use of the formula if it is not used for display. I thought this could be used to transform raw data into useful value, (voltage => temperature ...) that would display after conversion.

vdomos commented 8 years ago

Same problem with incremental sensor type, like this in info.json :

        "1-wire counter diff": {
            "name": "Counter diff",
            "data_type": "DT_Number",
            "conversion": "",
            "incremental": true,
            "timeout": 0,
            "history": {
                "store": true,
                "duplicate": true,
                "max": 0,
                "expire": 0,
                "round_value": 0
            }
        },

Domoweb don't display the calculated differrence, only the raw value.

compteur

Exemple of a counter sensor in database:

+--------+-----------+---------------------+-----------+-----------+--------------------+
| id     | sensor_id | date                | value_num | value_str | original_value_num |
+--------+-----------+---------------------+-----------+-----------+--------------------+
| 183555 |       196 | 2015-12-28 10:57:03 |        41 | 41.0      |            9943622 |
| 183543 |       196 | 2015-12-28 10:56:13 |        46 | 46.0      |            9943581 |
| 183530 |       196 | 2015-12-28 10:55:23 |        35 | 35.0      |            9943535 |
| 183520 |       196 | 2015-12-28 10:54:33 |        45 | 45.0      |            9943500 |
+--------+-----------+---------------------+-----------+-----------+--------------------+

Domoweb only display the original_value_num, not the value_num.

I saw that the MQ publish it's like that:

{u'timestamp': 1451296372, u'sensor_id': 196, u'device_id': 97, u'stored_value': u'9943416'}
{u'timestamp': 1451296423, u'sensor_id': 196, u'device_id': 97, u'stored_value': u'9943455'}
{u'timestamp': 1451296473, u'sensor_id': 196, u'device_id': 97, u'stored_value': u'9943500'}

it's the original_value_num, that is publish.

In this documentation: http://docs.domogik.org/domogik/develop/en/package_development/plugins/json/sensors.html

The MQ message must be send after "formula", "incrementation" ... are apply,

Am I wrong?

cereal2nd commented 8 years ago

ok, some code reading i found a bug:

the incremental calculation will not be visible in the mq message. The formula should be visible there

vdomos commented 8 years ago

I don't understand, Did you do an update in Domogik develop for this bug ?

Here the core_sensor table for this sensor 196:

[domogik]> select id, device_id, name, data_type,formula, conversion, last_value, last_received  from core_sensor  where id=196;
+-----+-----------+--------------+-----------+---------+------------+------------+---------------+
| id  | device_id | name         | data_type | formula | conversion | last_value | last_received |
+-----+-----------+--------------+-----------+---------+------------+------------+---------------+
| 196 |        97 | Counter diff | DT_Number | NULL    |            | 63.0       |    1451331734 |
+-----+-----------+--------------+-----------+---------+------------+------------+---------------+

The last_value corresponds to the calculation of the difference counter.

In the same order, here a sensor with a formula:

[domogik]> select id, device_id, name, data_type,formula, conversion, last_value, last_received  from core_sensor  where id=190;
+-----+-----------+------------+---------------+------------------------------+------------+------------+---------------+
| id  | device_id | name       | data_type     | formula                      | conversion | last_value | last_received |
+-----+-----------+------------+---------------+------------------------------+------------+------------+---------------+
| 190 |        94 | Luminosity | DT_Brightness | round(VALUE / 2.2 * 1000, 1) |            | 0.9        |    1451332382 |
+-----+-----------+------------+---------------+------------------------------+------------+------------+---------------+
1 row in set (0.00 sec)

The last_value corresponds to the calculation of the formula too.

And in the history:

[domogik]> select * from  core_sensor_history where sensor_id=190 order by date desc limit 3;
+--------+-----------+---------------------+-----------+-----------+--------------------+
| id     | sensor_id | date                | value_num | value_str | original_value_num |
+--------+-----------+---------------------+-----------+-----------+--------------------+
| 191821 |       190 | 2015-12-28 21:02:55 |       0.9 | 0.9       |          0.0019528 |
| 191806 |       190 | 2015-12-28 21:01:40 |       1.1 | 1.1       |           0.002441 |
| 191793 |       190 | 2015-12-28 21:00:26 |         1 | 1.0       |          0.0021969 |
+--------+-----------+---------------------+-----------+-----------+--------------------+
3 rows in set (0.06 sec)

Another thing, Domoweb seems to use the MQ to display the values of sensors: Here a copy of firefox console:

domoweb_ws_mq_1

And unfortunately the MQ message does not contain the last_value !

fritz-smh commented 8 years ago

Is there still the issue on domoweb side ?

vdomos commented 8 years ago

No, it't ok for me.