Newbie: Help With Simplifying Code


#1

1) Give a description of the problem
Trying to clean up my code! Would also love help with defining veriables!

2) What is the expected behaviour?
Expected behavior is happening, just wanting to know if it can look better.

3) What is happening/not happening?
The event is happening correctly!

4) Post a Green Snapshot of the pistonimage

So, as most of you will be able to tell, I am very new to all of this and wanted some basic help cleaning this kind of code up.

Is there any way to make it so it would be 70-100 instead of having to type out every number?

Thanks guys!


#2

Seems to me it could just be.

If Sensor changes(Trigger)
     IF value >69
         Set color
     else
         Set color

#3

Thanks, Terminal.

I am going to work on this, I really appreciate the help. Love WebCore, would love to use it to it’s full capabilities.


#4

You could also use ‘enters range’ for a trigger and ‘is inside of range’ for a condition. Then you can set the maximum and minimum.


#5

Thank you Guxdude!

Love the tips from you guys, it is super helpful. Just got into home automation during my time at home because of the outbreak, and the community has been amazing.


#6

So, I tried this method out, and I cannot get it to work properly.

5/28/2020, 12:18:23 PM +208ms
+1ms ╔Received event [My home].test = 1590686303205 with a delay of 3ms
+45ms ║RunTime Analysis CS > 21ms > PS > 4ms > PE > 19ms > CE
+50ms ║Runtime (36911 bytes) successfully initialized in 4ms (v0.3.110.20191009) (44ms)
+53ms ║╔Execution stage started
+64ms ║║Condition #2 evaluated false (6ms)
+71ms ║║Comparison (string) 100 is (string) >69 = false (1ms)
+73ms ║║Condition #3 evaluated false (7ms)
+74ms ║║Condition group #1 evaluated false (state did not change) (16ms)
+77ms ║║Cancelling statement #4’s schedules…
+1036ms ║║Executed physical command [Kitchen Lights].setColor([[hex: #FAEBD7, hue:9, saturation:78, level:91]]) (936ms)
+1037ms ║║Executed [Kitchen Lights].setColor (957ms)
+1040ms ║╚Execution stage complete. (987ms)
+1041ms ╚Event processed successfully (1041ms)


#7

By the way, I know I need to change that to a logical and, but for testing I wanted both to be conditions to run.


#8

rather then ‘is’ you need to select ‘is greater than’ for your condition and then remove the ‘>’ so it treats as a number and not a string.

BTW, if you reply to people’s comments or reference them directly using ‘@name’ they will get a notification directly and likely respond quicker.


#9

Thanks again @guxdude


#10

@guxdude so here is my issue now - I don’t see ‘is greater than’ as an option for my weather conditions.


#11

Hmm. That is based on the data type for that particular value I would say store it in a variable or cast it but then you might not be able to trigger on it.


#12

You may have to use a “greater than” Expression such as:

gt(value1, value2) ? true : false

Here is the Wiki link for more info.


But normally, math does not work as a trigger.

The logic is:

  • To run the piston, the trigger must fire… but…
  • The trigger cannot fire without math being done… and of course…
  • To calculate math, the piston has to be running… but again…
  • The piston cannot run unless the trigger fires… etc ad nauseam

#13

I also noticed the attribute you are trying to trigger on is preceded by a little house symbol. That means that attribute is not full supported like other attributes of the device which is why I think you get limited options. Not sure of all he ramification but perhaps @wcmore is.


#14

I wondered if this had something to do with it, as I am not using an actual weather station, just a virtual one through ST.

Is there a better way to implement weather into WebCore?

Also, thanks again, and thanks to @WCmore for the reply! This is all beyond helpful information that will be useful going foward. I appreciate you guys coming down to a newbie level! Ha!


#15

WebCoRE has pretty good weather provided by The Weather Company. You can see all the data available on the wiki at weather


#16

@guxdude Thanks for the link. I will have to do some reading on that, as I have no idea how to get things like $twcweather.conditions.precip1Hour into my code.

It’s been a good trial and error process!


#17

@guxdude I think I am on the right track! It’s an expression! DUH! Says it right there on the TWC Weather table!

This is what I have got going now, I need to work on getting a trigger for this piston!

Honestly having fun with all this!

Thanks for the link pointing me in the right direction.


#18

You’re welcome. You are learning quick. Your piston is coming along. I think you just need to make the first if a trigger (like rises above 0.01].


#19

@guxdude you’re the best! Thanks again. Look forward to working with WebCore and using the forums if (more like when!) I hit another roadblock.

Super helpful guys, and very fast responses. Glad I found this community!