Hi,
I used to program in the past and want to be able to witte my own programs/scripts.
I try to get started with something simple.
I creates a simple switch called thuis
I can show the status in the markup card
Using snarky’s VAR integration I could create a variable X by adding this to the configuration.yaml
What I want is every time I set the switch on is to increase X with 1 and dispaly that in de marup card
I have no clue where to start with this.
I guess I need to wriste a script for that and I tried:
‘’’
alias: test varx
description: “”
trigger:
platform: state
entity_id:
input_boolean.afwezig
from: “off”
to: “on”
condition: []
action:
service: notify.persistent_notification
data:
message: weggegaan
X=X+1
mode: single
‘’’
But I see nothing happening and when I reload the YAML code that X=X+1 is removed
For starters, please use proper formatting by using this button:
if not, it’s going to be difficult to see what you’re trying to do, as yaml is very strict in indentation
Hi,
I hope I have the proper topic and formatting now after posting in a wrong topic. If it is moved by a moderator please inform me where it goes?
I used to do some programming in the past in Pascal and *051 assembler and I want to be able to witte my own programs/scripts.
I try to get started with something simple.
I created a simple switch called thuis
I can already show the statusof that switch in the markup card
Using snarky’s VAR integration I could create a variable X by adding this to the configuration.yaml And I also can see the value of X in markup
What I want is every time I set the switch from of to on, to increase X with 1 and dispaly that in de marup card
I have no clue where to start with this.
I guess I need to write a script for that, and I tried this code
alias: test varx
description: ""
trigger:
- platform: state
entity_id:
- input_boolean.afwezig
from: "off"
to: "on"
condition: []
action:
- service: notify.persistent_notification
data:
message: weggegaan
X=X+1
mode: single
I don’t have experience with that integration you used to create a variable, but anyways, I would suggest using the native counter helper instead.
I’m other to do that, go to Settings > Devices and Services, select the tab Helpers and add a helper, selecting Counter as the type you want and following the required steps over there.
After creating the counter, use the counter.increment service in your automation.
Something like this:
alias: test varx
description: ""
trigger:
- platform: state
entity_id:
- input_boolean.afwezig
from: "off"
to: "on"
condition: []
action:
- service: counter.increment
data: {}
target:
entity_id: counter.your_new_counter
- service: notify.persistent_notification
data:
message: "Counter = {{ states('counter.your_new_counter')}}"
mode: single
But if you still want to use that integration, then it will be probably something like this (based on their docs, I’ve never used that as I mentioned:
Hi Thanks for your feedback.
This counter was just a simple example for testing that I canchage a vatiable after a trigger.
But this enlightens me a lot.
A thing that is simple in programming languages is quite different if you use YAML
At least I now know how much one must type to do such a simple thing like changing a variable a a trigger;)
Just used to a more ‘procedure’‘or function’ call system like I used to build old time state/event engines
As your goal is to learn, there’s another way to solve this which I probably will choose as it concentrates all the settings in a single entity and will probably be easier to maintain, which is using a template sensor.
Something like this:
template:
- trigger:
- platform: state
entity_id:
- input_boolean.afwezig
from: "off"
to: "on"
sensor:
- name: Variable X
unique_id: any_unique_id_for_variable_x
state: "{{ states('sensor.variable_x') | float(0) + 1.0 }}"
Yaml (Yet another markup language) is not a programming language at all, but a way of ordering, grouping and storing configuration lines (markup).
The use of templates comes closer and uses Jinja, but it still ain’t a programming language.
HA itself is written in Python, and by the sound of it, you want to have more of a ‘programming’ environment.
For that i think AppDeamon, or Pyscript, come closer, or when you are more in to Java, try NodeRed. Node Ref also takes a while to get used to, but it does enable you to use plain java when needed.
The is also a c# version around somewhere, but can’t find the link right now
Thnaks all for the info. This sure helps me further.
For programming I think I will take the Java or python way.
I will look which one I like most, but think the more formal Java might win but I will try some pythong to.
I found a nice turorial on python on W3