@MJFox wrote:
Hi!
Since it took me a while to get all the peaces together I would like to share with you how to read and write global variables in Fibaro.
I’m using an input slider to set the air temperature and the value of the input slider gets stored in a global variable in Fibaro. If I change the global variable in Fibaro the value gets synced to the slider accordingly:
First we need a rest_command:
rest_command: set_fibaro_var: method: put url: "http://192.168.1.31/api/globalVariables/{{ var }}" username: !secret fibaro_user password: !secret fibaro_password payload: '{"value":"{{ value }}"}' headers: Content-Type: application/json
Make sure you change the IP-adress to whatever your Fibaro Home Center is set to and set “fibaro_user” and “fibaro_password” in your secrets.yaml. Keep in mind that only super users are allowed to set global variables!
Next we need an input number. This is the value that is being controlled by the slider in your lovelace interface:
input_number: temperature_air: name: Air Temperature min: 20 max: 30 step: 0.5
Next we need a sensor to store the value of the global variable:
sensor: - platform: rest username: !secret fibaro_user password: !secret fibaro_password authentication: basic resource: "http://192.168.1.31/api/globalVariables/air_temperature" name: get_air_temperature value_template: '{{ value_json.value }}'
Make sure you change the IP-address and the name of the variable you want to read (“air_temperature” in my example).
Finally we need two automations to read and write the variable:
automation: - alias: set air temperature trigger: platform: state entity_id: input_number.temperature_air action: service: rest_command.set_fibaro_var data_template: var: "air_temperature" value: "{{ trigger.to_state.state }}" - alias: get air temperature trigger: platform: state entity_id: sensor.get_air_temperature action: service: input_number.set_value data_template: entity_id: input_number.temperature_air value: "{{ trigger.to_state.state }}"
Make sure you change
var: “air_temperature”
to the name of the variable you want to read/write.
After that you can add the entity “input_number.temperature_air” to your lovelace interface and it will be synced with the global variable.
Hope it helps!
Cheers
MJFox
Posts: 1
Participants: 1