Page 1 of 1

Blockly: Update value from blocky with a forumla (value + 1)

Posted: Monday 08 August 2016 20:20
by lagus
Hi there!

User story:
As $user I want to know when my weather station has stopped and are not updating the weather station values anymore.

To solve this I planned to count the times the weather station is sending the same value and if it is still sending the n time I'll notify.
If it's updated I'll reset the counter value to n=1

Here's my built out Blockly in Events:
Screenshot from 2016-08-08 20-12-52.png
Screenshot from 2016-08-08 20-12-52.png (50.2 KiB) Viewed 3255 times
(truncated the notification line...)

Unfortunately, as you can see, I'm missing the option to update the value of +1
Screenshot from 2016-08-08 20-15-43.png
Screenshot from 2016-08-08 20-15-43.png (12.25 KiB) Viewed 3255 times
but it is possible here:
https://developers.google.com/blockly/g ... eb/toolbox

Now, I'm sure there are other ways and probably smarter ways but as I'm not too good at writing my own scripts this is the solution I went for.
Are there any chance I can update the value as I wish with Blocky and Events in Domoticz or do I need to work with LUA or even turn to node-red?
Do I just not find the blocks or is it possible to add these functions into Events for Domoticz?

Many Thanks!

Edit: Placed attachments on the right place.

UPDATE: Added to my Blockly IF to reset the counter SET, Counter = 0, when message is sent

Re: Blockly: Update value from blocky with a forumla (value + 1)

Posted: Tuesday 09 August 2016 10:10
by mrf68
Hi,

for some testing purposes I created a virtual text sensor called Counter, I gave it value "0". The following LUA script reads the value, turns it into a number and when my PushOnButton is pressed, it adds 1 to the number and writes the value as a string into the text sensor (the idx of the sensor = 2). This way I can tell how often the button is pressed and it is shown on the Utility tab. Maybe you can use this as an example and create your own solution.

Code: Select all

counter = otherdevices_svalues['Counter']
counter = tonumber(counter)

commandArray = {}
if 
	devicechanged['PushOnButton'] == 'On'
then
	counter = counter + 1
	commandArray['UpdateDevice'] = 2 .. '|0|' .. tostring(counter)
end

return commandArray

Re: Blockly: Update value from blocky with a forumla (value + 1)

Posted: Tuesday 03 September 2019 16:44
by MadMedic
Thnx mrf08,
Reviving an old thread. Nevertheless this script was just what I was looking for.

Now for the next challenge:
only update the counter when button isn't pressed for at least half an hour or more.
(Or in my case, the backdoor isn't opened in more then half an hour.)
And resetting the count @ midnight

In any case: ^5 on leading me from blocky to lua