Timer - czas podlewania

Witam,
Stworzyłem prosty flow sterujący podlewaniem ogrodu. Dodałem pomocnika dzięki któremu mogę ustawić czas podlewania danej sekcji. Chciałbym stworzyć sensor widoczny w HA, który pokazywałby upływający czas do końca podlewania. Niestety poległem na tym etapie. Czy byłby ktoś w stanie pomóc mi rozwiązać ten problem?
Pozdrawiam

1 Like

Hej,
ja mam liczenie ale nie czasu pozostałego tylko ile już podlewa, zlicza cały dzień, żebym wiedział ile poszło, moze coś z tego sklecisz dla siebie

mam tak:

hfghtrhtr

flow:

[{"id":"2da2dc3512a08b03","type":"tab","label":"Flow 4","disabled":false,"info":""},{"id":"656c786c124c42cd","type":"zigbee2mqtt-out","z":"2da2dc3512a08b03","name":"","server":"e42dbc53.d003","friendly_name":"Zawór wody ","device_id":"0x847127fffe1aa32b","command":"state","commandType":"z2m_cmd","payload":"on","payloadType":"z2m_payload","transition":0,"x":630,"y":200,"wires":[]},{"id":"e8c65484e147318f","type":"server-state-changed","z":"2da2dc3512a08b03","name":"","server":"4d0e02c9.2307bc","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_boolean.zawor_wody","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":280,"y":260,"wires":[["656c786c124c42cd","6751fe425260a953","87a6b281c4be7f38"],["318a95bd4281d3b9","6a428f8b30a52300","1ba5521ea92d905e"]]},{"id":"318a95bd4281d3b9","type":"change","z":"2da2dc3512a08b03","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":640,"y":320,"wires":[["5bae5efdb16d5266","f3b1153ad64c22f4"]]},{"id":"6a428f8b30a52300","type":"zigbee2mqtt-out","z":"2da2dc3512a08b03","name":"","server":"e42dbc53.d003","friendly_name":"Zawór wody ","device_id":"0x847127fffe1aa32b","command":"state","commandType":"z2m_cmd","payload":"off","payloadType":"z2m_payload","transition":0,"x":630,"y":380,"wires":[]},{"id":"5bae5efdb16d5266","type":"delay","z":"2da2dc3512a08b03","name":"","pauseType":"delayv","timeout":"30","timeoutUnits":"minutes","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"x":860,"y":280,"wires":[["e5de1c4c04fd1415","3a9ac7b5f3197142"]]},{"id":"e5de1c4c04fd1415","type":"api-call-service","z":"2da2dc3512a08b03","name":"","server":"4d0e02c9.2307bc","version":3,"debugenabled":false,"service_domain":"input_boolean","service":"turn_off","entityId":"input_boolean.zawor_wody","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1080,"y":260,"wires":[[]]},{"id":"3a9ac7b5f3197142","type":"function","z":"2da2dc3512a08b03","name":"KOMUNIKAT","func":"msg.komunikat=\n{\n    \"data\":\n    {\n        \"message\": \"Skończone podlewanie\",\n    }\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1110,"y":340,"wires":[[]]},{"id":"972b970d02bb56df","type":"server-state-changed","z":"2da2dc3512a08b03","name":"","server":"4d0e02c9.2307bc","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_number.czas_podlewania","entityidfiltertype":"exact","outputinitially":false,"state_type":"num","haltifstate":"","halt_if_type":"num","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":320,"y":500,"wires":[["c0acc4191a472126","0c8e967cc1642555"]]},{"id":"f32418e736f75ea3","type":"change","z":"2da2dc3512a08b03","name":"","rules":[{"t":"set","p":"czas_podlewania","pt":"global","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":840,"y":580,"wires":[[]]},{"id":"6751fe425260a953","type":"change","z":"2da2dc3512a08b03","name":"","rules":[{"t":"set","p":"delay","pt":"msg","to":"czas_podlewania","tot":"global"}],"action":"","property":"","from":"","to":"","reg":false,"x":640,"y":260,"wires":[["5bae5efdb16d5266","f3b1153ad64c22f4"]]},{"id":"1ba096b1e99aaeb5","type":"comment","z":"2da2dc3512a08b03","name":"Ustawienie czasu podlewania","info":"","x":260,"y":440,"wires":[]},{"id":"dfd1fdc36e7a1a4a","type":"inject","z":"2da2dc3512a08b03","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":"600","topic":"","payloadType":"date","x":220,"y":580,"wires":[["fec2305602151185"]]},{"id":"fec2305602151185","type":"api-current-state","z":"2da2dc3512a08b03","name":"","server":"4d0e02c9.2307bc","version":2,"outputs":1,"halt_if":"","halt_if_type":"num","halt_if_compare":"is","entity_id":"input_number.czas_podlewania","state_type":"num","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"x":500,"y":580,"wires":[["f32418e736f75ea3"]]},{"id":"9f467cd960771746","type":"debug","z":"2da2dc3512a08b03","name":"Current Payload","active":false,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":1080,"y":680,"wires":[]},{"id":"8ccf483c117c79c1","type":"counter","z":"2da2dc3512a08b03","inc":"1","name":"","x":660,"y":740,"wires":[["c3f6fe3bf4ac3c3b"]]},{"id":"c3f6fe3bf4ac3c3b","type":"function","z":"2da2dc3512a08b03","name":"[s] to [hh:mm:ss]","func":"\nvar time = (new Date(msg.payload * 1000)).toUTCString().match(/(\\d\\d:\\d\\d:\\d\\d)/)[0];\nmsg.payload = time;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":880,"y":740,"wires":[["3b732d8c5dc662ba","9f467cd960771746"]]},{"id":"3b732d8c5dc662ba","type":"ha-entity","z":"2da2dc3512a08b03","name":"","server":"4d0e02c9.2307bc","version":1,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"timer_podlewanie"},{"property":"device_class","value":""},{"property":"icon","value":""},{"property":"unit_of_measurement","value":"m"}],"state":"payload","stateType":"msg","attributes":[],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","outputOnStateChange":false,"outputPayload":"","outputPayloadType":"str","x":1070,"y":740,"wires":[[]]},{"id":"5defa03af1c36bfe","type":"link in","z":"2da2dc3512a08b03","name":"","links":["87a6b281c4be7f38"],"x":175,"y":740,"wires":[["99d7a099ca954e18"]]},{"id":"87a6b281c4be7f38","type":"link out","z":"2da2dc3512a08b03","name":"","links":["5defa03af1c36bfe"],"x":395,"y":200,"wires":[]},{"id":"1ba5521ea92d905e","type":"link out","z":"2da2dc3512a08b03","name":"","links":["0f62f075fedd3e01"],"x":395,"y":320,"wires":[]},{"id":"0f62f075fedd3e01","type":"link in","z":"2da2dc3512a08b03","name":"","links":["1ba5521ea92d905e"],"x":175,"y":800,"wires":[["058fceae489fe90d"]]},{"id":"99d7a099ca954e18","type":"delay","z":"2da2dc3512a08b03","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":280,"y":740,"wires":[["891dc79e376ae2be"]]},{"id":"891dc79e376ae2be","type":"trigger","z":"2da2dc3512a08b03","name":"","op1":"1","op2":"0","op1type":"str","op2type":"str","duration":"-1","extend":false,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":480,"y":740,"wires":[["8ccf483c117c79c1"]]},{"id":"058fceae489fe90d","type":"change","z":"2da2dc3512a08b03","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":440,"y":800,"wires":[["891dc79e376ae2be"]]},{"id":"0c8e967cc1642555","type":"function","z":"2da2dc3512a08b03","name":"Ustaw czas podlewania","func":"msg.payload=\n{\n    \"timer\": msg.payload,\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":670,"y":500,"wires":[["ad8a38bf5f9a0943"]]},{"id":"ad8a38bf5f9a0943","type":"mqtt out","z":"2da2dc3512a08b03","name":"","topic":"zigbee2mqtt/0x847127fffe1aa32b/set","qos":"1","retain":"true","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"2871dfb9.e5e5d","x":950,"y":500,"wires":[]},{"id":"c0acc4191a472126","type":"function","z":"2da2dc3512a08b03","name":"","func":"\nmsg.payload=parseFloat(msg.payload).toFixed(0)*60000;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":620,"y":540,"wires":[["f32418e736f75ea3"]]},{"id":"da5d61485b4ba240","type":"comment","z":"2da2dc3512a08b03","name":"Wyzwolenie podlewania","info":"","x":240,"y":140,"wires":[]},{"id":"c04e53261b88f152","type":"change","z":"2da2dc3512a08b03","name":"Reset","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":570,"y":680,"wires":[["8ccf483c117c79c1"]]},{"id":"11c9c62a390ea0d4","type":"inject","z":"2da2dc3512a08b03","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"00 01 * * *","once":false,"onceDelay":0.1,"topic":"","payloadType":"date","x":430,"y":680,"wires":[["c04e53261b88f152"]]},{"id":"df22e929efbc4b8f","type":"comment","z":"2da2dc3512a08b03","name":"Liczenie czasu podlewania","info":"","x":250,"y":640,"wires":[]},{"id":"f3b1153ad64c22f4","type":"delay","z":"2da2dc3512a08b03","name":"","pauseType":"delay","timeout":"31","timeoutUnits":"minutes","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"x":870,"y":220,"wires":[["e5de1c4c04fd1415"]]},{"id":"f9ef11a7835e6b42","type":"inject","z":"2da2dc3512a08b03","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":900,"y":340,"wires":[["3a9ac7b5f3197142"]]},{"id":"e42dbc53.d003","type":"zigbee2mqtt-server","name":"zigbee2mqtt XPENOLOGY","host":"192.168.5.102","mqtt_port":"1883","mqtt_username":"","mqtt_password":"","tls":"","usetls":false,"base_topic":"zigbee2mqtt"},{"id":"4d0e02c9.2307bc","type":"server","name":"Asystent domowy","version":1,"legacy":false,"addon":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true},{"id":"2871dfb9.e5e5d","type":"mqtt-broker","name":"MQTT xpenology","broker":"192.168.5.102","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]
2 Likes

Dzięki, jutro usiądę i będę kombinował :grinning:

Niestety nie do końca mi to wciąż wychodzi. Stworzyłem kolejnego pomocnika “minutnik” i teraz chciałbym podmienić wartość duration na wartość zadaną w pomocniku “input_numer.czas_podlewania_sekcji”.
Czy można to zrobić za pomocą funkcji?
W miejsce xxx mogę wpisać ilość sekund natomiast nie mam pojęcia jak połączyć to innym pomocnikiem, np. typu “Numer”

najpierw event state z tym minutnikiem i potem nod change, zapisz sobie do flow.minutnik wartość payload tego pomocnika

potem funkcja przed call service:

var minutnik= flow.get('minutnik');
msg.payload=
{
    "data":
    {
        "duration": minutnik,
    }
}
return msg;

Wciąż jest cos nie tak. Mogłbyś spojrzeć co robię nie tak. Wielkie dzięki za pomoc!!!

flows (1).json (2,1 KB)

ok czyli chcesz inaczej,
prosze:

[{"id":"fe8a8c8cb38aecbd","type":"api-current-state","z":"de45045c.c5a7f8","name":"czas podlewania","server":"2fd88d3.44feb72","version":2,"outputs":1,"halt_if":"","halt_if_type":"num","halt_if_compare":"is","entity_id":"input_number.czas_podlewania_sekcji","state_type":"num","blockInputOverrides":false,"outputProperties":[{"property":"minutnik","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":350,"y":660,"wires":[["5e946c735b8b4030"]]},{"id":"ba0839c7276c0a7a","type":"inject","z":"de45045c.c5a7f8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":160,"y":660,"wires":[["fe8a8c8cb38aecbd"]]},{"id":"5e946c735b8b4030","type":"function","z":"de45045c.c5a7f8","name":"","func":"msg.payload=\n{\n    \"data\":\n    {\n        \"duration\": msg.minutnik,\n    }\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":540,"y":660,"wires":[["71942de458a44351"]]},{"id":"71942de458a44351","type":"api-call-service","z":"de45045c.c5a7f8","name":"","server":"2fd88d3.44feb72","version":3,"debugenabled":false,"service_domain":"timer","service":"start","entityId":"timer.test","data":"","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":720,"y":660,"wires":[[]]},{"id":"2fd88d3.44feb72","type":"server","name":"Home Assistant","version":1,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

Super, a czy wiesz może jak zrobić aby timer (nod: call service) odczytywał czas zapisany w pomocniku jako minuty a nie sekundy?

Dodaj

/60

i będą minuty :stuck_out_tongue:

Hehe ok, jeszcze raz dzięki za pomoc :grinning:

Kiedyś znalezione w necie i na potrzeby przerobione .
Konfiguracja
input_boolean.yaml

czas_podlewania_odczyt:
  name: Czas_polewania odczyt

czas_podlewania_pauza:
  name: Czas_podlewania_pauza 

input_number.yaml


czas_podlewania:
    name: 'Czas Podlewania'
    icon: mdi:timer
    min: 5
    max: 100
    step: 1
    unit_of_measurement: mins

Screenshot - 16.08.2021 , 13_26_45

Kod:
licznik podlewania.json (7,5 KB)

Przesuniecie suwaka uruchamia automatycznie licznik.
Zakres czasu można zmienić w input_number.yaml
Czas ustawiany w minutach, natomiast czas upływający w sekundach .

Dzięki za pomoc, teraz ja poprzerabiam na swoje potrzeby :wink:

Cześć
próbuje odtworzyć twoje flow, ale zdaje się że czegoś mi brakuje a nie rozumiem tego
zależy mi na zliczaniu czasu jak długo mam włączony przełącznik

Czy powinienem doinstalować tą intergacje z hacs?

tak, musisz mieć integracje rozszerzającą możliwości NR w HA

Zrobiłem

Uruchamianie encji z trybem uczenia się
Czyli:
włączam tryb uczenia się (czyli jak długo w sekundach ma działać urządzenie)
włączam switch => wyłączam =>następuje zapis do licznika
wciskam przycisk timer start i encja działa przez zmierzony czas, następnie się wyłącza
użycie suwaka również zmienia czas w liczniku i od raza uruchamia switch w ustawionym czasie po czym wyłącza
przycisk timer stop powoduje zatrzymanie odliczania i wyłączenie switcha
switch to poprostu jakaś encja - do testów wziąlem pompke w domu, ale może być np wentylator jakiś

a mój cel, to zrobienie prostego robota spawalniczego (już jest)
czyli kładę element na spawarkę=>włączam tryb uczenia=> odpalam proces spawania =>mierzy długość spawu w postaci czasu => i już mam powtarzany proces spawania dla takich samych elementów :grin:

obraz
flows(1).json (17,6 KB)

Mam pytanie w którym miejscu trzeba przestawić aby licznik i suwak liczył w minutach

Witam mogłby mi pan wysłać ten flow bo sobie nie daje rady a chce zrobic cos podobnego do zalaczania sniatla na dany czas ustawiany w ha

Musisz podać do kogo kierujesz swoją prośbę, wstawiając znak @ i nazwę.