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

A way to retrieve the total ON/OFF time of an outlet? #34

Closed
giuliomagnifico opened this issue Nov 23, 2022 · 5 comments
Closed

A way to retrieve the total ON/OFF time of an outlet? #34

giuliomagnifico opened this issue Nov 23, 2022 · 5 comments
Labels
question Further information is requested

Comments

@giuliomagnifico
Copy link

giuliomagnifico commented Nov 23, 2022

Hi and thanks a lot for this plugin. It's fabulous, I hope it will be keep alive and improved, I just built some of my stat panels (see screenshot), but I was wondering: is there a way to build a panel with the total time of an outlet when is ON?

Probably it would be just a workaround like divide the time by the number of entries etc... but I'm struggling to figure out the correct way, because the exporter use only the 1-0 status but not the timestamp, maybe is possible to implement it? Or any other way to retrieve the same result?

Thanks!

casa

@giuliomagnifico giuliomagnifico added the question Further information is requested label Nov 23, 2022
@lstrojny
Copy link
Owner

lstrojny commented Nov 23, 2022

This should be possible with sum_over_time (homebridge_outlet_on[$__range]). This calculates the "on"-time relative to the currently selected range. So if you have selected 24 hours it would tell you how long it was on in that timeframe.

image

Here is the JSON for the graph

``` { "id": 19, "gridPos": { "x": 0, "y": 0, "w": 8, "h": 8 }, "type": "gauge", "title": "Panel Title", "targets": [ { "refId": "A", "datasource": { "type": "prometheus", "uid": "3ad6c16d-4ef5-409b-a6dd-10ae8f486d7d" }, "editorMode": "code", "expr": "sum_over_time (homebridge_outlet_on[$__range])", "legendFormat": "{{name}}", "range": true } ], "options": { "reduceOptions": { "values": false, "calcs": [ "lastNotNull" ], "fields": "" }, "orientation": "auto", "showThresholdLabels": false, "showThresholdMarkers": false }, "fieldConfig": { "defaults": { "mappings": [], "thresholds": { "mode": "percentage", "steps": [ { "color": "blue", "value": null }, { "value": 50, "color": "#EAB839" } ] }, "color": { "mode": "thresholds" }, "unit": "m" }, "overrides": [] }, "datasource": { "uid": "3ad6c16d-4ef5-409b-a6dd-10ae8f486d7d", "type": "prometheus" }, "pluginVersion": "9.2.5" } ```

@giuliomagnifico
Copy link
Author

giuliomagnifico commented Nov 23, 2022

Thanks for the quick reply but... uh, I don't have the homebridge_outlet_on metric. Only the homebridge_switch_outlet_in_use that has only 0 or 1 has value and I can't use the sum over time function.

Screenshot 2022-11-23 at 13 40 40

I'm using the last release: homebridge-prometheus-exporter v0.0.14 and my outlets are from Meross.

Edit: here are all the metrics from your the exporter:

homebridge_battery_charging_state
homebridge_battery_level_percentage
homebridge_battery_status_low_battery
homebridge_fanv2_active
homebridge_fanv2_rotation_direction
homebridge_fanv2_rotation_speed_percentage
homebridge_fanv2_swing_mode
homebridge_humidity_sensor_current_relative_humidity_percentage
homebridge_input_source_current_visibility_state
homebridge_input_source_is_configured
homebridge_input_source_target_visibility_state
homebridge_input_source_type
homebridge_lightbulb_brightness_percentage
homebridge_lightbulb_on
homebridge_switch_current_consumption_w
homebridge_switch_on
homebridge_switch_outlet_in_use
homebridge_switch_voltage_v
homebridge_television_active
homebridge_television_active_identifier
homebridge_television_sleep_discovery_mode
homebridge_television_speaker_active
homebridge_television_speaker_mute
homebridge_television_speaker_volume_control_type
homebridge_television_speaker_volume_percentage
homebridge_temperature_sensor_current_temperature_celsius
homebridge_thermostat_current_heating_cooling_state
homebridge_thermostat_current_relative_humidity_percentage
homebridge_thermostat_current_temperature_celsius
homebridge_thermostat_target_heating_cooling_state
homebridge_thermostat_target_temperature_celsius
homebridge_thermostat_temperature_display_units

@lstrojny
Copy link
Owner

Well, same there, try sum_over_time (homebridge_outlet_in_use[$__range]).

@giuliomagnifico
Copy link
Author

giuliomagnifico commented Nov 23, 2022

Okay thanks, this worked: sum_over_time(homebridge_switch_outlet_in_use[$__range]). I don't have only the "outlet" metric, it fails to retrieve the data. My metric is switch_outlet. Don't know why...

Anyway unfortunately for me it doesn't work in a very reliable way because almost all my outlets look like ON/1, because when the watt consumption is above 0, they appears like ON, also if they're in standby. For some appliances, like the microwave or TV, they figure alway ON because during the standby the power consumption is 3-4W. So I have to insert also a query that exclude the outlets with less than 3W of consumption.

If you have any suggestion I would be thankful :)

@lstrojny
Copy link
Owner

You could maybe do something like some_wattage > bool 3 and then count those over time to get the usage in time.

Closing this issue now as it’s more of a prometheus query question for which there are better resources.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants