Quantcast
Channel: Configuration - Home Assistant Community
Viewing all 108143 articles
Browse latest View live

Need this to be translated from PHP to Ninja/automation

$
0
0

Hi guys!

I’m working on a water-play-tile (outside) whicn means: a tile with 5 holes in it with water coming out. Now i’'ve built all logic in PHP. But now i’m trying to translate it to Ninja or whatever is needed.

But i dunno where to start. Is it even possible what i want? Or is another way easier?

Own writtten PHP code:

<?php

$pins = ['water_pin_14', 'water_pin_16', 'water_pin_17', 'water_pin_18', 'water_pin_19'];
$scriptStarted = true; // will be finaly a switch-check in home assistant
$maxIterations = 30;
$counter = 0;

$randomAmounts = [1,1,1,1,2,2,2,2,3,3,3,3,4,4,5,5];

while($scriptStarted and $counter < $maxIterations) {

    // Shuffle array
    shuffle($pins);
	
	// Shuffle randomAmounts
	shuffle($randomAmounts);
	
	// Pick random keys
	$randomPinKeys = array_rand($pins, $randomAmounts[0]);
	
	// If $randomPinKeys contains one element, it's unfortunately casted to int, cast it back to array
	if (is_numeric($randomPinKeys)) {
	    $randomPinKeys = [0 => $randomPinKeys];
	}
	
	
	// Turn off all pins
	foreach($pins as $pin) {
		echo 'turn off pin ' . $pin . PHP_EOL;
	}
	
	// Turn on random picked pins
	foreach ($randomPinKeys as $randomPinKey) {
		echo 'turning on pin ' . $pins[$randomPinKey] . PHP_EOL;
	}
	
	sleep(rand(2,8)); // Random wait between 3 and 8 seconds
	$counter++;
}

1 post - 1 participant

Read full topic


Purge MariaDB database - recorder.purge simple enough?

$
0
0

Hi!

I’ve been doing quite a bit of reading on this, and there is definitly a lot of information out there, but I’m confused by what is the best way to do this.

I have MariaDB setup and as you would expect, its getting bigger and making my backups more intense. I’ve set up an automation below to call the recorder.purge service when the DB is more than 3GB and to perfom the action anytime between 1 an 6 am. I’ve create the sensor for the MariaDB size, in another tutorial i read.

alias: 'Purge MariaDB Database '
description: When it reaches 3GB, perform purge and keep last 7 days after purge.
trigger:
  - platform: numeric_state
    entity_id: sensor.homeassistant_mariadb_size
    above: '3000'
condition:
  - condition: time
    before: '06:00:00'
    after: '01:00:00'
action:
  - service: recorder.purge
    data:
      keep_days: 7
mode: single

Is this all that I need to do? It seems pretty simple, but when I read the posts about this, its sounds more complicated.

thanks for your help.

1 post - 1 participant

Read full topic

Browser mod: Popups not working on Firefox/Chrome: FINE on Safari

$
0
0

Weird right?
Double checked it wasn’t a pop-up blocker or security feature (I think). They work as they always have on Safari, but on Chrome/Firefox my double-clicks just yield… nothing.
Will post some sample YAML for reference:

Lovelace yaml:

      - type: custom:button-card
        template: newlightbtn
        entity: light.hue_color
        double_tap_action: !include ../popup/table_lamp_popup.yaml
        name: Table lamp
        icon: mdi:lamp
        view_layout:
          grid-area: bt1

Popup:

action: fire-dom-event
browser_mod:
  command: popup
  title: []
  style: 
    light-entity-card$: |
        ha-card {
          background: none;
          box-shadow: none;}
    
  card:
    effects_list: false
    type: custom:light-entity-card
    hide_header: false
    header: Table lamp
    entity: light.hue_color
    color_picker: true
    brightness: true
    smooth_color_wheel: true
    full_width_sliders: true
    child_card: false

This all worked until upgrading to the newest version of HA. I did also reinstall browser_mod, so I don’t believe there is a version issue there.

Anyone experiencing this?

1 post - 1 participant

Read full topic

Creating a script with cheapest hour needed

$
0
0

Hi there

Trying to get a script that can calculate the time my charger for the car needs to run before tomorrow, but I am kind of lost, have this running in template, but how do I get it to only run when I want to (do not need a template)? and how do I get the diffrent values into som sensors???

{% set today_price = states.sensor.nordpool_kwh_dk1_dkk_2_095_025.attributes.today %}
{% set tomorrow_price = states.sensor.nordpool_kwh_dk1_dkk_2_095_025.attributes.tomorrow %}
{% set ev_car_battery_size =  89 -%}
{% set ev_car_end_charge_level  = 100 -%}
{% set ev_car_battery_charge_speed  = 10 -%}
{% set ev_car_charge_kwh = (ev_car_battery_size / 100 * (ev_car_end_charge_level - states('sensor.ford_hv_battery_percent') | float))  %}
{% set ev_car_charge_time_min = ((ev_car_charge_kwh / ev_car_battery_charge_speed) * 60) | round(0) -%}
{% set ev_car_charge_time_hour = (ev_car_charge_time_min / 60) |  round(0, 'ceil') %}

{% set future_price = today_price[now().hour:] + tomorrow_price -%} 
{% set inteval_start_tomorrow = 0 -%}
{% set interval_start_hour =  now().hour + 1 -%}
{% set interval_end_tomorrow = 1 -%}
{% set interval_end_hour = 23 -%}

{% set low_interval_length = ev_car_charge_time_hour -%}
{% set all_price = today_price + tomorrow_price -%}

{% set interval_price = all_price[interval_start_hour + 24 * inteval_start_tomorrow : interval_end_hour + 24 * interval_end_tomorrow] -%}
{% set last_considered_interval_index = (interval_price | length) - low_interval_length + 1 -%}
{% set ns = namespace(current_best_average=1000, current_best_index=-1) -%}  
{% for price in interval_price[:last_considered_interval_index] -%}
  {% set current_average =  interval_price[loop.index0:loop.index0+low_interval_length] | average -%}
  {% if current_average < ns.current_best_average -%}
    {%-set ns.current_best_average = current_average -%}
    {% set ns.current_best_index = loop.index0 -%}
  {% endif -%}
{% endfor -%}

{%- set start_index = ns.current_best_index %}
{%- set best_interval_price = interval_price[start_index:start_index + low_interval_length] %}
{% set best_interval_start_hour =  24 * inteval_start_tomorrow + interval_start_hour + start_index -%}
{%- set best_interval_price = interval_price[start_index:start_index + low_interval_length] %}

{% set ev_car_start_charge_datetime =  (now() + timedelta(hours=best_interval_start_hour - now().hour)) - timedelta(minutes = now().minute) %}

{% set ev_car_stop_charge_datetime =  ev_car_start_charge_datetime + timedelta(minutes=ev_car_charge_time_min+10) %}

{% if ev_car_end_charge_level > states('sensor.fordhv_battery_percent') | float -%}
  Mustang GT Ladning: {{ states('sensor.ford_hv_battery_percent') | float }}% til {{ ev_car_end_charge_level }}% 
  Beregning udført : {{ now().strftime('%H:%M den %d/%m') }}
  Ladetid          : {{ ev_car_charge_time_hour - 1 }} time(r) og {{ ev_car_charge_time_min  % 60 }} min
  Hvor meget strøm : {{ ev_car_charge_kwh | round(1) }} kWh
  Det koster ca    : {{ (ev_car_charge_kwh * (best_interval_price| average))| round(0, 'ceil') }} kr
  kWh prisen er    : {{ (best_interval_price| average)| round(2) }} kr
  Start lader      : {{ ev_car_start_charge_datetime.strftime('%Y-%m-%dT%H:%M') }}
  Stop lader       : {{ ev_car_stop_charge_datetime.strftime('%Y-%m-%dT%H:%M') }}
{% else -%}
  Mangler ikke ladning
{% endif -%}

Hopefull sombody can help me in a directons, just needs a idea or direction how to solve it. I need a lot more than this, but this is to get me started.

BTW it is my first template…

BR

Tue

1 post - 1 participant

Read full topic

Safely move Home Assistant Database hosted by MariaDB addon from old to new hardware

$
0
0

I need to move my Home Assistant ecosystem from an old to new hardware.

Actually running on Raspberry Pi 4 booting from SSD with Debian 11 and HA Supervised.
Want to move to a VM under Proxmox with HassOS operating system.

Creating a snapshoot on old hardware and restoring on new seems fine except for MariaDB database that become corrupted.

Database is big and I want to preserve it.

I suppose I could stop MariaDB addon and take a snapshot to get a non-corrupted snapshot but creating a snapshoot is very time-consuming on Pi. I also need to repeat the database migration several times in these days while I test several things. So even doing several times a sql dump is not viable. I would like a faster method because I can’t stop addon for hours every time.

Best approach, I think, could be using mariabackup possibly with replication among old and new host, but mariabackup seems not installed in the addon.

I read about a file copy method of databases folder while engines are stopped, I was trying to do it but on HassOS data folder of addon_core_mariasb seems unaccessible (or I don’t know how to access because the /mnt/data/supervisor path seems not existing).

So what is a fast and safe way to move MariaDB database between old and new host?

There are already many topic on this issue I hope there is now a solution.

1 post - 1 participant

Read full topic

Defining tap-able areas in lovelace

$
0
0

I have multiple picture elements in a single card that blend together so there aren’t any visible overlaps for lighting and so that creating the images is uniform and fast.

The problem with this is that there’s no way to distinguish between the tap-action areas for each image (i.e. each light) without adding icons or other buttons to address the light.

What I’d like to be able to do is tap a room and have that light respond, or tap and hold and set the brightness.

At this point, in the list of elements under the picture-elements card, the most recent, or the last element defined is the one that is seen as the tap-action control.

Is there a way to define tap action areas on a lovelace screen that are invisible and can be positioned with accuracy?

1 post - 1 participant

Read full topic

Wrong device asignation - ZHA Tuya TS0044 switch

$
0
0

Hi every one,

I am trying to configure a Tuya switch with Conbee II coordinator on ZHA.

On the surface of the Switch is the Model-Nr written: ESW-0ZAA-EU which according to the Zigbee device compatibly repository corresponds to the model TS0044. My coordinator discovers the model TS004F. This one is very similar, but with fewer functionalities.

I was trying to solve the issue myself, but I have not that much experience on this, and I am starting to think I was fooled on AliExpress.

Can anyone tell me how I check if it’s a wrong device assignation from my coordinator?

Can I force the coordinator to use another model configuration?

I would be grateful if anyone can share a good manual with basics for such things. I am a newbie on zigbee

Thanks
mvk

1 post - 1 participant

Read full topic

Removed DuckDNS now possible NGinx issue?

$
0
0

I just removed DuckDNS/Lets encrypt because I moved to Nabu Casa for my remote access. I removed my SSL certfiles from my configuration.yaml and now I have issues accessing NodeRed, Grafana, & Visual Studio Code through the Web UI in the add on.

I changed ssl: false in the add on config and can access NodeRed by http://MyLocalIP:1880 but get error trying though add on Web UI - 404: Unauthorized

Error in Supervisor as I try to access the Web UI:

22-03-20 11:59:40 WARNING (MainThread) [supervisor.api.ingress] No valid ingress session None
22-03-20 12:00:10 WARNING (MainThread) [supervisor.api.ingress] No valid ingress session None
22-03-20 12:00:29 WARNING (MainThread) [supervisor.api.ingress] No valid ingress session None

Something to do with NGinx and my previous ssl certificates? I’m not sure where to start with NGinx…

any help appreciated

1 post - 1 participant

Read full topic


Motion sensor automation with additional features

$
0
0

Hello Community!

I would need your help. Namely, I want to create a single (if that is even possible) automation that will allow me to do everything of the following list. I would like to make the automation as efficient as possible. From what I’ve read in the various URIs, this will also require helpers.

  1. when motion detected → light on
  2. if no motion detected for a short time, light off (use the Aqara Motion Sensors without hardware hack)
  3. light should be switched on only from a certain brightness (about 20 lx)
  4. light should have less brightness in the night than in the evening (evening → 70 %, night → 1 %)
  5. before the light goes out in the evening, dim it to 30 % (when motion is detected, dim it back to 70 %)

Now my question: Is this at all possible in an automation? Does anyone of you possibly already have one or the other automation that goes in this direction? Or would NodeRED be the better choice in this regard, since the Aqara sleep without hack for a minute.

1 post - 1 participant

Read full topic

Check for existence of file using shell_command

$
0
0

How can I get and use a return of a shell script like this?

find -f /path/file

1 post - 1 participant

Read full topic

Only first action in sequence gets executed

$
0
0

Hello. I made the following blueprint to try to attribute an action to each button of my Hue remotes. Everything works very well except only the first action in a sequence gets executed. Any idea why this is? So if I set, for example, for a given button, a sequence to delay 1sec and then activate a scene, no scene gets ever activated. I can’t figure this out… Thanks in advance.

blueprint:
  name: Philips Hue Dimmer Switch control
  description: 'Control lights with a Philips Hue Dimmer Switch. Set an action for each button. Note: You have to pick an action for each event. If you don’t want to react to an event, choose a Delay of 0sec.'
  domain: automation
  input:
    remote:
      name: Dimmer Switch Action sensor
      description: Select your entity that will control this
        automation.
      selector:
        entity:
          domain: sensor
    action_on-press:
      name: on-press
      description: select action to run when you press I
      default: []
      selector:
        action: {}
    action_off-press:
      name: off-press
      description: select action to run when you press O
      default: []
      selector:
        action: {}
    action_up-press:
      name: up-press
      description: select action to run when you press UP
      default: []
      selector:
        action: {}
    action_down-press:
      name: down-press
      description: select action to run when you press DOWN
      default: []
      selector:
        action: {}
    action_on-hold:
      name: on-hold
      description: select action to run when you hold I
      default: []
      selector:
        action: {}
    action_off-hold:
      name: off-hold
      description: select action to run when you hold O
      default: []
      selector:
        action: {}
    action_up-hold:
      name: up-hold
      description: select action to run when you hold UP
      default: []
      selector:
        action: {}
    action_down-hold:
      name: down-hold
      description: select action to run when you hold DOWN
      default: []
      selector:
        action: {}
mode: restart
trigger:
- platform: state
  entity_id: !input 'remote'
action:
- variables:
    command: '{{ trigger.to_state.attributes.action }}'
- choose:
  - conditions:
    - '{{ command == ''on-press'' }}'
    sequence: !input 'action_on-press'
  - conditions:
    - '{{ command == ''off-press'' }}'
    sequence: !input 'action_off-press'
  - conditions:
    - '{{ command == ''up-press'' }}'
    sequence: !input 'action_up-press'
  - conditions:
    - '{{ command == ''down-press'' }}'
    sequence: !input 'action_down-press'
  - conditions:
    - '{{ command == ''on-hold'' }}'
    sequence: !input 'action_on-hold'
  - conditions:
    - '{{ command == ''off-hold'' }}'
    sequence: !input 'action_off-hold'
  - conditions:
    - '{{ command == ''up-hold'' }}'
    sequence: !input 'action_up-hold'
  - conditions:
    - '{{ command == ''down-hold'' }}'
    sequence: !input 'action_down-hold'
  default: []

1 post - 1 participant

Read full topic

State_filter not working with ":"

IKEA Tradfri shortcut button as trigger

$
0
0

Hi,
I had reset my home assistant (corrupt ssd and no complete backup) and I´ve used this to reconfigure my setup. Now I´ve a separate raspi with a deconz docker container. I´ve to learn all my zigbee devices to this new deconz instance but thats fine :). One thing I´ve trouble with it are my IKEA tradfri shortcut buttons. I can´t use the device as a trigger so I´m using deconz_event as a trigger but I´m confused about the logging entry:

From where comes the entry ... fired event 'Short press'? And could I use this a a trigger instead of the deconz_event?

Anybody knows it and would help me please?

Bye,
Michael

1 post - 1 participant

Read full topic

4 Button Secene Switch can not be controlled correctly by ZHA

Manage automations

$
0
0

As most users i wrote my first automations using the UI editor. As some automations get more and more sophisticated and complicated i’m now on the point to move some out from automations.yaml to separate files which get included from the configurations.yaml. Afte BTW: r struggling with the documentation it’s now “working”. The following are the handicaps and or problems i found so far. I list it together with ideas how it could be solved. BTW: The reason i put the more complicated automations in separate file is DOCUMENTATION: I learned that when using the UI editor comments are not allowed (except in the documentation field). Documentation is essential to understand what the programmer had in mind.

  • no comments allowed: → I propose to introduce a “comment” field in every section: Trigger, condition, action, choose, … This alone would eliminate the need to split automations into separate files, in most cases.

  • New function in UI editor: Save as … : → to save an automation as separate file instead of within the huge automations.yaml. I realised that moving an automation away is hard work, and error prone.

  • Yaml within UI editor: The information text in a yellowish box preceding the YAML code uses to much space. → either allow a more advanced mode that simply hides this information boxes, OR squeeze it to a single line. → Similar: hide/eliminate all the explaining text in almost every section. Its not anymore needed after a while.

  • The automations overview shows UI enabled (automations.yaml) and MANual automations without any differentiations. When trying to edit a manual-mode automation a info box pops up saying ´´Only automations in automations.yaml are editable´´ - stupid! → Make manual-mode automations visible as such: different color, icon,… → allow a code editor to be called to edit such automations.

  • The automations overview should… → allow to directly open the YAML editor. Without calling first the UI editor. → show the documentation text field. → should have an option to print the automation.

  • x-ref of all used resources: Over the short time i’m using HA and writing automations i more and more use Helpers, Scenes, and scripts. → There should be a cross reference that helps keeping the overview.

I like the UI editor, it generates error free code. But is uses to much space on my screen and does not allow comments.
.

1 post - 1 participant

Read full topic


Homematic TRVs showing as n/a after restart

$
0
0

Hi all,
I have installed Raspberrymatic and have successfully added 5 TRVs.
They are visible and accessible on my Lovelace dashboard where I can control their setpoint temperature, see the current temperature or select programs.
However, after each restart they are unavailable in Lovelace, showing N/A everywhere.

Only after I go to Raspberrymatic and select one of them and for example change the temperature they become available in Lovelace as well. Sometimes they also seem to loose the connection when switching from manual to auto mode. But this does not happen every time.

Does this have to do with the V_last_reboot script and automation? I have followed the instructions (even the latest update where homematic was replaced with raspberrymatic in the template) but either this has got nothing to do with the solution or something is not working.
Also the sensor which should show the time and date of the last reboot always shows 01.01.1970 00:00. Is this the way it should be?

I love the integration but would like to fix this. Would very much appreciate your help.

Thanks and regards,

Merc

1 post - 1 participant

Read full topic

How do I subtract a time-based value from another?

$
0
0

I have two helpers: text.helper01 and text.helper02
They both contains values based on a timer. Like %H:%M:%S:%f (ex. 10:46:24:756321)
How do I subtract one time-value from the other?

For example text.helper01 has the value of 10:45:00:000000
and text.helper02 has the value 10:48:30:000000
I want to make a Automation with an Action for text.helper02 minus text.helper01 and take the
result of 00:03:30:000000 and set it as a value for a third helper called text.helper03

1 post - 1 participant

Read full topic

Problem with automation putting something in google calendar

$
0
0

Hello everyone,

I try to put something in my google calendar via an automation but keep getting this error: “You need to have writer access to this calendar”.
What am I doing wrong or how can I solve this?
Thanks for every response.

1 post - 1 participant

Read full topic

Changing Icon Color based on state in picture-elements?

$
0
0

Uh…so, I’m lost on this one.

I’m trying to overlay an icon on my picture-elements setup and I want to customize the on and off colors. Right now, the entity and icon is a light/light bulb, and the resulting icon is either blue when off, or some shade of yellow when on, depending on brightness.

I just want to be able to control the color.

- type state-icon
  entity: light.workshop
  style:
    top: 20%
    left: 20%

Now, how do I change the color of this icon based upon the state of the entity?

1 post - 1 participant

Read full topic

Automation file split with gui edit

$
0
0

Hey guys,
I finally decided to make the jump and start splitting my config files.
First thing I wanted to do is to split the automation file into multiple yaml files.
I used the !include_dir_merge_list instruction to provide a folder where all automation files will reside, but I noticed it doesn’t give me the ability to edit in the gui when I do that. I saw in some post that home assistant gui doesn’t work when you have your yaml files inside folders. So I decided I would just specify 2 automation locations like this:

automation: !include_dir_merge_list misc/automation/
automation: !include automations.yaml

I figured I will use the automations.yaml for the automation that will be editable in the gui, and the folder for the yaml automation files that is not editable in the gui. But when I did that it looks like it disabled all automations I have. It’s llisted in the gui but looks disabled.

Any idea how to achieve this?
Thanks for any helps with this.

1 post - 1 participant

Read full topic

Viewing all 108143 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>