LordMike / MBW.BlueRiiot2MQTT

Utility to map between Blue Riiots pool API, and Home Assistant MQTT
49 stars 2 forks source link

[Feature-Request] Add/remove pump schedules via mqtt #17

Closed NemoN closed 3 years ago

NemoN commented 4 years ago

would be a nice feature to add/remove pump schedules from mqtt because my pump is triggered from home automation system.

Screenshot_20200715-142138_Blueriiot

LordMike commented 4 years ago

So how would this work?

You want to change the schedule on BR, when your pump starts, to "now .. +4 hours", and then when the pump stops, change it to "manual" ?

NemoN commented 4 years ago

Good question. I hadn't really thought about the details yet. Are measurements taken when the pump is set to "manual" but "activated"? Then it would be enough to activate and deactivate the pump (in BR) via MQTT. (And to leave it on mode manual)

ggggh commented 4 years ago

I'm confused too :) This project only captures measurements, it doesn´t manage pumps or know about them. I, like you, have integrated it with my pump, but that is external to this project.

LordMike commented 4 years ago

I'll gladly consider writing back to BlueRiiot.. but in general I'd prefer if settings and configuration were done in the app, as it is after all designed for just that.

I don't think the pump settings affect the measurements in any way.. then again, I haven't looked that much into it. I would think that the details would be used to discard measurements taking during the pump's operation so that any outliers in those periods can be ignored.

ggggh commented 4 years ago

Ah, starting to understand this maybe... Is this for the case where the blueriiot is integrated within your pump tubing, rather than floating on the pool, so we should only consider values when there is actually water flowing in the tubing?

NemoN commented 4 years ago

Sorry i missed this important point. Yes the blueriiot is integrated into the tubing (using the BlueFit 50). I have only valid measurements if the pump is running. This i why we can enter the pump schedule into the App (then the App is only showing measurements within the timerange). Now i want to trigger the pump from ioBroker (HA). I this case it could be that the pump is running, but blueriiot thinks it is not (because the static schedule not match).

ggggh commented 4 years ago

Right...I understand it now! So you would like either the schedule to be returned within the messages (maybe a topic stating if pump running or not, so you can then decide to ignore the rest of the values), or even no messages sent at all while pump is not running

LordMike commented 4 years ago

But wouldn't BR then only show you the current readings... for all time..

What I mean is .. If you set it to 02:00 to 05:00, can you see yesterdays 07:00 reading?..

Or will it discard any readings right now ... f.ex. if you set it to 02:00 to 05:00, will a reading at 03:00 be stored, while 01:00 will be ignored ? ...

NemoN commented 4 years ago

But wouldn't BR then only show you the current readings... for all time..

What I mean is .. If you set it to 02:00 to 05:00, can you see yesterdays 07:00 reading?..

Or will it discard any readings right now ... f.ex. if you set it to 02:00 to 05:00, will a reading at 03:00 be stored, while 01:00 will be ignored ? ...

If i enable the scheduled pump running times in BR i see only readings within the configured time-range. all other readings (if any?) are ignored or not shown to me in the frontend.

NemoN commented 4 years ago

Looks like with dynamic pump runtimes I have to set the value at BR to manual and then ignore all values where the pump is off.

LordMike commented 4 years ago

@NemoN did you find out if changing pump schedules was necessary?

... also.. should this app make any effort to not track values, outside of pump schedules? ... I didn't catch if BR stops measuring whenever pumps are off. If they still make measurements (but just don't show them) ... I'd have to do something to handle that.. :P

LordMike commented 4 years ago

At least from the above,

If i enable the scheduled pump running times in BR i see only readings within the configured time-range. all other readings (if any?) are ignored or not shown to me in the frontend.

I can conclude that setting the pump schedule to "now and 4 hours" whenever you turn on the pump, does not make sense. Also, setting the schedule to have BR stop reporting static/unchanging values from a Fit-50 mount, doesn't make sense.

Did you @NemoN decide if you wanted this app to do something? .. I don't think we can get HASS to ignore values if some other condition is met.. ... Maybe I should have a "disable updates" topic that you can send "yes" and "no" to, which temporarily stops fetching values ?

ggggh commented 4 years ago

I'd agree - I think the master for the pump schedule is not blueriiot, so we shouldn't treat it as such. Whatever is mastering your pump automation via a schedule should handle ignoring the readings from blueriiot when the pump is off - either by sending an mqtt to disable readings for that period, or just ignoring them when they come back in during that timeframe.

LordMike commented 4 years ago

... and the ignoring of messages on HASS... is that possible?

Else the only option we have is my app not sending any.

... it's not possible.

ggggh commented 4 years ago

Ah, ok - I don't know HASS, but I'm assuming maybe not ignoring the message itself, but ignoring or disabling actions/alarms/triggers on it should be do-able.

NemoN commented 4 years ago

@LordMike Sorry I'm late, I'm on vacation. For me it would be enough if I could switch the pump mode on/off via MQTT. Not the real pump. I mean the pump setting in the BR app (see first screenshot - the first setting) Would that be possible?

LordMike commented 4 years ago

I'll look into it.

gllmlbrt commented 4 years ago

Hi there, I have the same setup as @NemoN and I was frankly wondering about the exact same things. Essentially the issue is getting readings while the pump is off, meaning that the BR tells you the water quality of the water stagnating in the pipe which is not a real useful/valid information. Now based on the discussion I realize that the app may deal with that already with pump schedule, and then in Hass we have to find out what is the difference between a reading received over mqtt within the pump-on schedule and pump-off time.

Just thinking and writing here: Now what would be REALLY neat would be that, the pump schedule defined in the app is transmitted over MQTT,

-then read by Hass and the pump is then activated for that schedule via on-off switching method in place in hass (for me it is a Sonoff PowR2 tasmotized over mqtt

-or directly over mqtt. It could just be a publication of cmnd/Power on or off from the BlueRiiot2MQTT docker app, based on the BR app schedule, bypassing entirely hass ? That would effectively make the BR app the scheduling method for the pump, instead of the multiple automations/scripts needed in hass... and ensure full consistency between what is in BR app and the real pump schedule.

LordMike commented 4 years ago

My thinking is that the only way to make this good, is to not send data to HASS that HASS doesn't need. So it has to stop at this app. This is in order to fix multiple things, such as the Recorder not logging invalid data, automations not having to account for on/off etc.. everything is just easier when the data you receive is valid.

So how to block it in this app.

I'm fond of the idea of letting my app read the pump timings from BR, as I've always wanted you guys to use the BR app for everything BR.. So if I did that, I could parse it and do the (hopefully) same logic as BR, and not submit readings that are outside the pump schedules.

Does this require being able to push pump schedules via MQTT?

gllmlbrt commented 4 years ago

I'm fond of the idea of letting my app read the pump timings from BR, as I've always wanted you guys to use the BR app for everything BR.. So if I did that, I could parse it and do the (hopefully) same logic as BR, and not submit readings that are outside the pump schedules.

Yes that would be the original idea, for those with the FIT50 mounted on the piping.

Does this require being able to push pump schedules via MQTT?

That would be only useful for my secondary idea which is that once the schedule is sent over mqtt, we can do what we want with it, including mastering the actual pump switch...

Ideally, and simplistically it would be only a publication of "on" or "off" from your app in line with the BR app schedule, then we can use that to convert into whatever mqtt command to our pump or anything else.

ggggh commented 4 years ago

I'd only like to suggest I personally wouldn't want to master the pump schedule from the BR app itself.
The reason is that for a full automation I make the pump schedule dependent on ORP and pH values.
I have my pump run based on a minimum number of hours of filtration a day, but especially have it come on ad-hoc when it needs to dose some acid or activate the chlorinator. If you've got your BR set up with the BlueFit..it gets more complicated. You need the pump to come on before you take a reading and then decide whether it needs to stay on or not. With the new predicted reading times you may be able to schedule the pump to come on shortly before the next reading happens - but it is a bit sketchy as not always totally predictable. If we could trigger a reading, would be much easier.

gllmlbrt commented 4 years ago

I'd only like to suggest I personally wouldn't want to master the pump schedule from the BR app itself.

Noted, and if the only thing the @LordMike app does is publish and on/off message based on BR app schedule, we are all free to ignore it.

The reason is that for a full automation I make the pump schedule dependent on ORP and pH values.

Do you mind sharing your config automation, I am curious and I looked for inspiration as well ?

LordMike commented 4 years ago

So, I'll try to make:

I'm not sure about this part,

Ideally, and simplistically it would be only a publication of "on" or "off" from your app in line with the BR app schedule, then we can use that to convert into whatever mqtt command to our pump or anything else.

Do you want, in addition to a sensor describing the schedule, another (binary) sensor that is "BR pump schedule says it's active"? ... a sensor that in reality has nothing to do with BR, but is merely to help with other things so they don't have to parse time ranges?

LordMike commented 4 years ago

Oh god.. the pump schedules in the API.. they hurt my brain...

image

I've set three schedules:

So not only do BR store this as timestamps... they've messed completely with the dates. Notice the last one, which starts on the 19th and ends on the 18th..

Oh well..

LordMike commented 4 years ago

I have working code for fetching and setting of the pump schedules.

image

LordMike commented 4 years ago

A docker image should be building. Give dev a whirl and see what happens.

Notes:

LordMike commented 4 years ago

No comments - @NemoN @ggggh @Nordicfastware ? :)

NemoN commented 4 years ago

@LordMike just back from vacation, will test it asap.

NemoN commented 4 years ago

@LordMike works perfect for me!

MQTT pub:

# mosquitto_pub -h localhost -t blueriiot/commands/pool/1234-xxx/set_pump_schedule -m manual
# mosquitto_pub -h localhost -t blueriiot/commands/pool/1234-xxx/set_pump_schedule -m none
# mosquitto_pub -h localhost -t blueriiot/commands/pool/1234-xxx/set_pump_schedule -m '[["07:00", "10:00"],["16:00", "17:00"]]'

MQTT sub:

blueriiot/commands/pool/1234-xxx/set_pump_schedule manual
blueriiot/pool_1234-xxx/pump_schedule/state Manual
blueriiot/pool_1234-xxx/pump_schedule/attributes {"pool_id":"1234-xxx"}
blueriiot/commands/pool/1234-xxx/set_pump_schedule none
blueriiot/pool_1234-xxx/pump_schedule/state None
blueriiot/pool_1234-xxx/pump_schedule/attributes {"pool_id":"1234-xxx"}
blueriiot/commands/pool/1234-xxx/set_pump_schedule [["07:00", "10:00"],["16:00", "17:00"]]
blueriiot/pool_1234-xxx/pump_schedule/state Scheduled
blueriiot/pool_1234-xxx/pump_schedule/attributes {"pool_id":"1234-xxx","schedule":"07:00-10:00, 16:00-17:00","schedules":2,"schedule_0":"07:00-10:00","schedule_0_start":"07:00","schedule_0_end":"10:00","schedule_1":"16:00-17:00","schedule_1_start":"16:00","schedule_1_end":"17:00"}

All other pool settings in the app seems to be ok.

LordMike commented 4 years ago

Due to other issues, the feature is also in v0.8

LordMike commented 4 years ago

Cool. If you have any comments on the format of arguments etc, place them here - I'll take a look when I have time.

I don't know how to use this in any automations, so if it's easier f.ex. to have a series of numbers, like 7,10,16,17 ... then I could do that.. Can also do multiple formats.

Same goes for the output, the HASS sensor. I don't know if the format I've chosen is easy to use in automations - but give it a whirl :)